[Haskell-cafe] Displaying infered type signature of 'offside'
functions
Georg Sauthoff
g_sauthoff at web.de
Sat Apr 28 14:32:19 EDT 2007
Hi,
I like the strong static type system of Haskell for various
reasons. One reason is, that it makes easier to understand new
code. I.e. when I read code I type ':t foo' in ghci/hugs from
time to time, to check my own idea of the type signature, if it
is not included in the source code.
Well, ':t ' doesn't work withwith non-top-level/local functions
(or does it?).
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 first looked at the GHC-API, but I found this comment in
http://darcs.haskell.org/ghc/compiler/main/GHC.hs :
- NOTE:
-- - things that aren't in the output of the typechecker right now:
[..]
-- - type signatures
Hm, is this comment in sync with the current GHC source?
Then I looked at the ghc options. '-ddump-types' only dumps the
signatures of global functions ...
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).
Best regards
Georg Sauthoff
More information about the Haskell-Cafe
mailing list