Infer type of a string containing a Haskell expression -
i need (quick , dirty) way representation of type of haskell expression given string.
i see 3 options:
- use ghc api -- however, documentation loses me pretty quickly.
- use other type inference tool -- i've been suggested try haskell-type-exts, fails type trivial expressions. don't know of other such tool.
- roll own hm inferer -- i'd avoid unless absolutely necessary
i don't need complete solution, in sense library/tool can type reasonable basic subset of haskell suffice me.
so simplest way achieve this?
the hint
package offers restricted, perhaps more understandable interface ghc api. perhaps sufficient purposes? if not, can perhaps @ sources better idea of how use ghc api directly.
here's example program:
import language.haskell.interpreter main :: io () main = r <- runinterpreter $ setimports ["prelude"] typeof "map (+1)" either print putstrln r
if run, prints
num b => [b] -> [b]
Comments
Post a Comment