Haskell: getting the static type of an expression

前端 未结 2 1072
死守一世寂寞
死守一世寂寞 2020-12-25 08:23

I\'m looking for a function that does what the GHCi :type command does.

Ideally, it would have a signature something like

getStaticType :: a -> St         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-25 09:09

    try http://www.haskell.org/haskellwiki/GHC/As_a_library

    typed targetFile targetModule = do
     defaultErrorHandler defaultFatalMessager defaultFlushOut $ do
      runGhc (Just libdir) $ do
    
       dflags <- getSessionDynFlags
       let dflags' = xopt_set dflags Opt_ImplicitPrelude
       setSessionDynFlags dflags'
    
       target <- guessTarget targetFile Nothing
       setTargets [target]
       load LoadAllTargets
    
       m <- getModSummary $ mkModuleName targetModule
       p <- parseModule m
       t <- typecheckModule p
    
       return $ typecheckedSource d
    

提交回复
热议问题