git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Make it work with non-fully-qualified data types
commit4249ca0235517b40e6694fdb8e076dcdb95edb74 authorBenjamin Kovach] <bkovach5@uga.edu> dateSat 2 Aug 2014, 18:49 (12 years ago) parent44607c4
1 file changed+22−7
psci/Main.hs+22−7
psci/Main.hs+22−7
@@ -257,6 +257,18 @@ createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetB
257257 in
258258 P.Module moduleName ((importDecl `map` imports) ++ decls) Nothing
259259
260+-- |
261+-- Makes a volatile module to hold a non-qualified type synonym for a fully-qualified data type declaration.
262+--
263+createTemporaryModuleForKind :: PSCiState -> P.Type -> P.Module
264+createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports, psciLetBindings = lets} typ =
265+ let
266+ moduleName = P.ModuleName [P.ProperName "Main"]
267+ importDecl m = P.ImportDeclaration m Nothing Nothing
268+ itDecl = P.TypeSynonymDeclaration (P.ProperName "IT") [] typ
269+ in
270+ P.Module moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
271+
260272modulesDir :: FilePath
261273modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
262274
@@ -303,17 +315,20 @@ handleTypeOf value = do
303315handleKindOf :: P.Type -> PSCI ()
304316handleKindOf typ = do
305317 st <- PSCI $ lift get
306− let m = createTemporaryModule False st (P.BooleanLiteral True) -- dummy value
318+ let m = createTemporaryModuleForKind st typ
307319 mName = P.ModuleName [P.ProperName "Main"]
308320 e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("Main.purs", m)])
309321 case e of
310322 Left err -> PSCI $ outputStrLn err
311− Right env' -> do
312− let st = P.CheckState env' 0 0 (Just mName)
313− k = L.runStateT (P.unCheck (P.kindOf mName typ)) st
314− case k of
315− Left errStack -> PSCI . outputStrLn . P.prettyPrintErrorStack False $ errStack
316− Right (kind, _) -> PSCI . outputStrLn . P.prettyPrintKind $ kind
323+ Right env' -> -- P.types env' M.Map (Qualified ProperName) ([String], Type)
324+ case M.lookup (P.Qualified (Just mName) $ P.ProperName "IT") (P.typeSynonyms env') of
325+ Just (_, typ') -> do
326+ let st = P.CheckState env' 0 0 (Just mName)
327+ k = L.runStateT (P.unCheck (P.kindOf mName typ')) st
328+ case k of
329+ Left errStack -> PSCI . outputStrLn . P.prettyPrintErrorStack False $ errStack
330+ Right (kind, _) -> PSCI . outputStrLn . P.prettyPrintKind $ kind
331+ Nothing -> PSCI $ outputStrLn "Could not find kind"
317332
318333-- Commands
319334