[Haskell-cafe] Displaying infered type signature of 'offside'functions

Claus Reinke claus.reinke at talk21.com
Sat Apr 28 17:31:38 EDT 2007

> Thus I searched for a way to get this information for functions,
> which are defined offside (of the main indentation level).
> So, what tools do you use to get the inferred type signature of local
> functions?

i tend to do that by hand: if i write

    f .. = e
        where ..defs..


    f .. = rhs
        rhs = e 
        .. defs ..

i can replace rhs with anything in scope within f, and test or type it
in ghci. the trouble, of course, are the other calls to f, which don't
like the change in type. so instead i have to take f out of production
use, somewhat like this

    f .. = undefined
    f' .. = rhs
        rhs = e[f'/f] 
        .. defs[f'/f] ..

and use f' for testing and typechecking..

so, if you get your alternative to work, i'd be interested to add that
to my own vim scripts as well!-) it seems one needs to compile the
source before one can use -ddump-tc?

> But '-ddump-tc' includes type signatures of offside defined
> functions.
> I.e. something like
> ghc -ddump-tc Foo.lhs 2>&1 \
>      | awk '/^[A-Z].+lhs/, ! // { print $0; }' \
>      | awk '/ :: / , /\[\]/ { if (!($0 ~ /\[\]/)) print $0; }' \
>      | less
> does the trick.
> But as the haskell/ghc wiki mentions, the -ddump-* output is
> optimized for human reading and not for some kind of 'automatic
> use'. For automatic use one should look at the GHC-API ...
> Well, I mention this, because I would like to integrate some
> lookup feature (for type signatures) into vim (if it doesn't
> exist yet).

GHC-API would be the preferred solution, but editor bindings
traditionally have to interpret all kinds of output not intended for 
anyone's consumption. you can certainly store the output, do 
substitutions, and associate types with identifiers via associative 
arrays, so you need only one call to get all local types, if you 
can extract and identify the information.


More information about the Haskell-Cafe mailing list