git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Make it work with non-fully-qualified data types
4249ca0Benjamin Kovach]
psci/Main.hs+22−7
@@ -257,6 +257,18 @@ createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetB
257 in
257 in
258 P.Module moduleName ((importDecl `map` imports) ++ decls) Nothing
258 P.Module moduleName ((importDecl `map` imports) ++ decls) Nothing
259
259
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+
260modulesDir :: FilePath
272modulesDir :: FilePath
261modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
273modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
262
274
@@ -303,17 +315,20 @@ handleTypeOf value = do
303handleKindOf :: P.Type -> PSCI ()
315handleKindOf :: P.Type -> PSCI ()
304handleKindOf typ = do
316handleKindOf typ = do
305 st <- PSCI $ lift get
317 st <- PSCI $ lift get
306− let m = createTemporaryModule False st (P.BooleanLiteral True) -- dummy value
318+ let m = createTemporaryModuleForKind st typ
307 mName = P.ModuleName [P.ProperName "Main"]
319 mName = P.ModuleName [P.ProperName "Main"]
308 e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("Main.purs", m)])
320 e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("Main.purs", m)])
309 case e of
321 case e of
310 Left err -> PSCI $ outputStrLn err
322 Left err -> PSCI $ outputStrLn err
311− Right env' -> do
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
312− let st = P.CheckState env' 0 0 (Just mName)
326+ let st = P.CheckState env' 0 0 (Just mName)
313− k = L.runStateT (P.unCheck (P.kindOf mName typ)) st
327+ k = L.runStateT (P.unCheck (P.kindOf mName typ')) st
314− case k of
328+ case k of
315− Left errStack -> PSCI . outputStrLn . P.prettyPrintErrorStack False $ errStack
329+ Left errStack -> PSCI . outputStrLn . P.prettyPrintErrorStack False $ errStack
316− Right (kind, _) -> PSCI . outputStrLn . P.prettyPrintKind $ kind
330+ Right (kind, _) -> PSCI . outputStrLn . P.prettyPrintKind $ kind
331+ Nothing -> PSCI $ outputStrLn "Could not find kind"
317
332
318-- Commands
333-- Commands
319
334