Is it possible to query the ghci for the type it inferred for a function inside another function?
+9
A:
You might try doing it by setting a breakpoint on it, so the function is in scope from the debugger.
Also I think that EclipseFP can tell you the types of things when you mouse over them, at least some of the time.
Paul Johnson
2010-01-24 20:31:23
Whoa, just realised that breakpoints where an option, after posting a convoluted half-baked solution... Then noticed this answer. GHCi prints out the types of expressions in current scope when it stops at a breakpoint without any special prodding, so it's just a matter of placement. +1!
Michał Marczyk
2010-01-24 20:38:42
Nice tip, but doesn't work if code doesn't compile. Tom's answer can come in handy.
Wei Hu
2010-01-25 03:32:09
+13
A:
This is a quick and ugly hack, but what I usually do is just use the function in the wrong way and read the error message:
inc x = x + 1
where
f (y, z) = y + z
g = f :: Char
GHCi output:
Couldn't match expected type `Char'
against inferred type `(t, t) -> t'
In the expression: f :: Char
Although this leaves out the context Num t =>
, this usually does provide me with enough information to continue.
Tom Lokhorst
2010-01-24 20:46:11