[Haskell-beginners] Working out the types
Daniel Fischer
daniel.is.fischer at googlemail.com
Tue Jul 5 21:24:10 CEST 2011
On Tuesday 05 July 2011, 19:55:43, Patrick LeBoutillier wrote:
> Hi all,
> Here's my question: Does ghci have a verbose mode or something where
> is can show you step by step how the types
> are worked out?
No. You can use it to get the types of subexpressions, though, and work
towards the complete expression from that:
Prelude> :t (:)
(:) :: a -> [a] -> [a]
Prelude> :t (. (:))
(. (:)) :: (([a] -> [a]) -> c) -> a -> c
Prelude> :t (map . (:))
(map . (:)) :: a -> [[a]] -> [[a]]
which gives you smaller gaps to fill in.
> If not is there a hackage (or any other kind of)
> package that can do that?
I'm not aware of any, but there might be.
>
> a lot, so I was wondering if such a program existed that could do it
> automatically.
Automatic type checkers do exist (every compiler/interpreter needs one),
but I don't think they have been written with the ability to output not
only the result but also the derivation.
For someone familiar with a particular type checker, it probably wouldn't
be hard to add that feature, but if it's a complicated beast like GHC's
type checker, becoming familiar with it would probably be a big
undertaking.
Writing your own much-reduced (able to parse and typecheck only a very
restricted subset of the language) might be easier, but probably working
from Mark P. Jones' "Typing Haskell in Haskell"
http://web.cecs.pdx.edu/~mpj/thih/
would be better than starting from scratch (it's somewhat oldish, so it
certainly doesn't cope with recent GHC extensions, but for everyday run-of-
the-mill problems, it should be working with only minor modifications).
More information about the Beginners
mailing list