@@ -24,6 +24,7 @@ import Control.Monad
24import Control.Monad.Trans.Class
24import Control.Monad.Trans.Class
25import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
25import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
26import Control.Monad.Trans.State.Strict
26import Control.Monad.Trans.State.Strict
27+import qualified Control.Monad.Trans.State.Lazy as L
27import Control.Monad.Error (ErrorT(..), MonadError)
28import Control.Monad.Error (ErrorT(..), MonadError)
28import Control.Monad.Error.Class (MonadError(..))
29import Control.Monad.Error.Class (MonadError(..))
@@ -256,6 +257,18 @@ createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetB
257 P.Module moduleName ((importDecl `map` imports) ++ decls) Nothing
258 P.Module moduleName ((importDecl `map` imports) ++ decls) Nothing
261+-- Makes a volatile module to hold a non-qualified type synonym for a fully-qualified data type declaration.
263+createTemporaryModuleForKind :: PSCiState -> P.Type -> P.Module
264+createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
266+ moduleName = P.ModuleName [P.ProperName "Main"]
267+ importDecl m = P.ImportDeclaration m Nothing Nothing
268+ itDecl = P.TypeSynonymDeclaration (P.ProperName "IT") [] typ
270+ P.Module moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
259modulesDir :: FilePath
272modulesDir :: FilePath
260modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
273modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
@@ -296,6 +309,27 @@ handleTypeOf value = do
296 Just (ty, _, _) -> PSCI . outputStrLn . P.prettyPrintType $ ty
309 Just (ty, _, _) -> PSCI . outputStrLn . P.prettyPrintType $ ty
297 Nothing -> PSCI $ outputStrLn "Could not find type"
310 Nothing -> PSCI $ outputStrLn "Could not find type"
313+-- Takes a value and prints its kind
315+handleKindOf :: P.Type -> PSCI ()
316+handleKindOf typ = do
317+ st <- PSCI $ lift get
318+ let m = createTemporaryModuleForKind st typ
319+ mName = P.ModuleName [P.ProperName "Main"]
320+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [("Main.purs", m)])
322+ Left err -> PSCI $ outputStrLn err
324+ case M.lookup (P.Qualified (Just mName) $ P.ProperName "IT") (P.typeSynonyms env') of
325+ Just (_, typ') -> do
326+ let chk = P.CheckState env' 0 0 (Just mName)
327+ k = L.runStateT (P.unCheck (P.kindOf mName typ')) chk
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"
299-- Commands
333-- Commands
@@ -339,6 +373,7 @@ handleCommand Reset = do
339 Left err -> psciIO $ putStrLn err >> exitFailure
373 Left err -> psciIO $ putStrLn err >> exitFailure
340 Right modules -> PSCI . lift $ put (PSCiState files defaultImports modules [])
374 Right modules -> PSCI . lift $ put (PSCiState files defaultImports modules [])
341handleCommand (TypeOf val) = handleTypeOf val
375handleCommand (TypeOf val) = handleTypeOf val
376+handleCommand (KindOf typ) = handleKindOf typ
342handleCommand _ = PSCI $ outputStrLn "Unknown command"
377handleCommand _ = PSCI $ outputStrLn "Unknown command"
344inputFiles :: Cmd.Term [FilePath]
379inputFiles :: Cmd.Term [FilePath]