[Haskell-cafe] Hoogle? [Stacking monads]
ryani.spam at gmail.com
Wed Oct 8 03:15:23 EDT 2008
On Tue, Oct 7, 2008 at 7:09 PM, Andrew Coppin
<andrewcoppin at btinternet.com> wrote:
> For my current troubles, it would be really useful if there were some
> program that you could feed some source code to, and it would tell you what
> the inferred types of each subexpression are. (Ideally it would be nice if
> you could use this on fragments that don't typecheck; being able to see what
> types are being inferred where could help explain why the type checker is
> unhappy, and ultimately where you went wrong. But I'm not sure how you could
> present the internal state in a digestible way.) I don't know if anybody has
> ever attempted such a tool...?
There is such a tool, it's called ghci :)
It just takes a bit of massaging to do what you want:
... some module code ...
function_that_does_not_typecheck = some_expression
function_that_does_not_typecheck = error "force typechecker to be happy"
For now lets assume that you are curious about the type of the subexpression
f some_func [a..b]
where f, a, and b are locally bound.
ghci> :set -fglasgow-exts
ghci> :t (?f some_func [?a .. ?b])
Here's an example:
Prelude> :t ?f map [?a .. ?b]
?f map [?a .. ?b] :: forall t a b t1.
?f::((a -> b) -> [a] -> [b]) -> [t1] -> t)
This tells you the types the variables have to have, and the type of
Judicious use of (undefined :: type_signature) can also help.
More information about the Haskell-Cafe