ghc-mod/Info.hs

25 lines
635 B
Haskell
Raw Normal View History

2010-11-12 07:27:50 +00:00
module Info where
import Control.Applicative
import GHC
import Outputable
import PprTyThing
import Types
2010-11-12 07:32:20 +00:00
typeExpr :: Options -> String -> String -> IO String
typeExpr _ expr file = (++ "\n") <$> typeOf file expr
2010-11-12 07:27:50 +00:00
2010-11-12 07:32:20 +00:00
typeOf :: String -> String -> IO String
typeOf fileName expr = withGHC $ do
2010-11-12 07:27:50 +00:00
initSession []
setTargetFile fileName
load LoadAllTargets
setContextFromTarget
pretty <$> exprType expr
where
setContextFromTarget = do
2010-11-15 03:14:38 +00:00
ms <- depanal [] False
mdl <- findModule (ms_mod_name (head ms)) Nothing
2010-11-12 07:27:50 +00:00
setContext [mdl] []
pretty = showSDocForUser neverQualify . pprTypeForUser False