
On Tue, Oct 7, 2008 at 7:09 PM, Andrew Coppin
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. Then 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. (Enum t1, ?b::t1, ?a::t1, ?f::((a -> b) -> [a] -> [b]) -> [t1] -> t) => t This tells you the types the variables have to have, and the type of the expression. Judicious use of (undefined :: type_signature) can also help. -- ryan