[Haskell-cafe] Displaying infered type signature of 'offside' functions

Simon Peyton-Jones simonpj at microsoft.com
Tue May 1 11:57:13 EDT 2007


| 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.

The principal difficulties here are to do with "what do we want" rather the implementation challenges.

1.  Should the compiler print the type of every declaration? Should GHCi allow you to ask the type of a local decl?

2.  How should the variables be identified?  There may be many local bindings for 'f', so you can't say just ":t f".  Ditto if dumping all local bindings.

3.  Do you want all locally-bound variables (including those bound by lambda or case), or just letrec/where bound ones?   I think 'all', myself, but there are a lot of them.

4.  (This is the trickiest one.)  The type of a function may mention type variables bound further out.  Consider
        f :: [a] -> Int
        f xs = let v = head xs in ...

The type of 'v' is simply 'a'.  Not 'forall a. a', but rather 'if xs:[a] then *that* a!'  In general there may also be existential type variables bound by an enclosing pattern match too.

So it's not easy to see how to report v's type.  In general there is no type signature for f, which only makes matters worse, since there is no name to use for the in-scope type variable.


These are all user-interface issues.  If some people would like to thrash out a design, and put it on the Wiki, I think there is a good chance that someone (possibly even me) would implement it.

Simon


More information about the Haskell-Cafe mailing list