@@ -24,6 +24,7 @@ import Control.Monad
2424import Control.Monad.Trans.Class
2525import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
2626import Control.Monad.Trans.State.Strict
27+import qualified Control.Monad.Trans.State.Lazy as L
2728import Control.Monad.Error (ErrorT(..), MonadError)
2829import Control.Monad.Error.Class (MonadError(..))
2930
@@ -256,6 +257,18 @@ createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetB
256257 in
257258 P.Module moduleName ((importDecl `map` imports) ++ decls) Nothing
258259
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} 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+
259272modulesDir :: FilePath
260273modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
261274
@@ -296,6 +309,27 @@ handleTypeOf value = do
296309 Just (ty, _, _) -> PSCI . outputStrLn . P.prettyPrintType $ ty
297310 Nothing -> PSCI $ outputStrLn "Could not find type"
298311
312+-- |
313+-- Takes a value and prints its kind
314+--
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)])
321+ case e of
322+ Left err -> PSCI $ outputStrLn err
323+ Right env' ->
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
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"
332+
299333-- Commands
300334
301335-- |
@@ -339,6 +373,7 @@ handleCommand Reset = do
339373 Left err -> psciIO $ putStrLn err >> exitFailure
340374 Right modules -> PSCI . lift $ put (PSCiState files defaultImports modules [])
341375handleCommand (TypeOf val) = handleTypeOf val
376+handleCommand (KindOf typ) = handleKindOf typ
342377handleCommand _ = PSCI $ outputStrLn "Unknown command"
343378
344379inputFiles :: Cmd.Term [FilePath]