module Hint.Conversions (
typeToString, kindToString, moduleToString, isSucceeded
) where
import qualified Hint.GHC as GHC
import Hint.Base
typeToString :: MonadInterpreter m => GHC.Type -> m String
typeToString :: forall (m :: * -> *). MonadInterpreter m => Type -> m String
typeToString Type
t
= do
PrintUnqualified
unqual <- RunGhc m PrintUnqualified
forall (m :: * -> *) a. MonadInterpreter m => RunGhc m a
runGhc forall {n :: * -> *}.
(MonadIO n, MonadMask n) =>
GhcT n PrintUnqualified
forall (m :: * -> *). GhcMonad m => m PrintUnqualified
GHC.getPrintUnqual
(DynFlags -> m String) -> m String
forall (m :: * -> *) a.
MonadInterpreter m =>
(DynFlags -> m a) -> m a
withDynFlags ((DynFlags -> m String) -> m String)
-> (DynFlags -> m String) -> m String
forall a b. (a -> b) -> a -> b
$ \DynFlags
df ->
String -> m String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> m String) -> String -> m String
forall a b. (a -> b) -> a -> b
$ DynFlags -> PrintUnqualified -> SDoc -> String
GHC.showSDocForUser DynFlags
df PrintUnqualified
unqual (Type -> SDoc
GHC.pprTypeForUser Type
t)
kindToString :: MonadInterpreter m => GHC.Kind -> m String
kindToString :: forall (m :: * -> *). MonadInterpreter m => Type -> m String
kindToString Type
k
= (DynFlags -> m String) -> m String
forall (m :: * -> *) a.
MonadInterpreter m =>
(DynFlags -> m a) -> m a
withDynFlags ((DynFlags -> m String) -> m String)
-> (DynFlags -> m String) -> m String
forall a b. (a -> b) -> a -> b
$ \DynFlags
df ->
String -> m String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> m String) -> String -> m String
forall a b. (a -> b) -> a -> b
$ DynFlags -> SDoc -> String
GHC.showSDoc DynFlags
df (Type -> SDoc
GHC.pprTypeForUser Type
k)
moduleToString :: GHC.Module -> String
moduleToString :: Module -> String
moduleToString = ModuleName -> String
GHC.moduleNameString (ModuleName -> String)
-> (Module -> ModuleName) -> Module -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Module -> ModuleName
forall unit. GenModule unit -> ModuleName
GHC.moduleName
isSucceeded :: GHC.SuccessFlag -> Bool
isSucceeded :: SuccessFlag -> Bool
isSucceeded SuccessFlag
GHC.Succeeded = Bool
True
isSucceeded SuccessFlag
GHC.Failed = Bool
False