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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -