I am trying to typecheck a code snippet provided as a string.
I found the package haskell-type-exts (hackage link) which seems to provide what i need: With parseModule
an AST gets constructed on which typecheckModule
can be applied. But then I don't know what to do with the result. It is of type Tc VarEnv
where Tc
is a monad.
The package provides a test case where something like this is used:
ea <- runTc testEnv $ typecheckExp e
But runTc
is in a hidden module so I cannot use it. Here is the code I have so far:
import Language.Haskell.Exts.Parser (parseModule, ParseResult(..))
import Language.Haskell.TypeCheck.TypeCheck
-- import Language.Haskell.TypeCheck.Monad --hidden module
main = do
let m = "myTest = map (+1) [1..10]"
let r = parseModule m
case r of
ParseOk res -> printStuff res
_ -> print "wtf"
printStuff r = do
let Right tc = return $ typecheckModule r
-- print tc?
What am I missing here? Maybe the module is only hidden by mistake?
I think this package is not yet ready for usage. Just look at the source of Language.Haskell.TypeCheck. For example typeCheck = undefined
typechecks of course!
You could try to use the GHC-API (Haddock and Wiki Page).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With