[Haskell-cafe] What's the problem with iota's type signature?

wren ng thornton wren at freegeek.org
Thu May 28 23:14:43 EDT 2009


michael rice wrote:
> Yeah, I went back and tried double again, though I'd swear I got the dang thing to compile  (and run) w/o errors.
> 
> I guess I meant Num. So Num is a class and Int and Integer are types? What are the other classes? Docs?
> 
> Unification, for me, is pattern matching ala Prolog. What's the meaning in Haskell? Docs?
> 
> I've been digging into this stuff for months and it's still tripping me up. Very frustrating.


As others have mentioned, using GHCi can give you a lot of information. 
GHCi commands begin with a colon followed by the command (kinda like 
vi), whereas anything not beginning with a colon is treated as a Haskell 
expression to be evaluated. The :? command will list all the GHCi 
commands, which is a good place to start.

The :type command takes a Haskell expression and prints the type 
inferred for it. You can also use the command ":set +t" which will make 
GHCi print the type after evaluating each expression; you may want to 
use this until you get the hang of things. The :info command takes a 
whitespace separated list of identifiers and will print their type and 
other information (e.g. what module it comes from, what type class a 
function belongs to, all the functions that are members of a type class, 
fixity of operators,...)


As far as type classes and the like, there are a bunch. Hoogle[1] is an 
excellent API search engine for looking up this kind of stuff. Just 
enter the name of a function, type class, data type, or enter a type 
signature. The results give links to the online Haddock documentation 
(either GHC official docs, or Hackage docs).


Unification is used when doing type inference. It's the same unification 
as in Prolog, only at the type level. Because of the way inference 
works, it happens that the |a| and |b| type variables must be unified 
for both of the functions you gave. A whole lot more can be said here, 
though I'm not sure how much you care :)  The Wikipedia page on 
Hindley--Milner[2] gives a good starting point, though Haskell's type 
inference has more bells and whistles than the basic HM algorithm.


[1] http://haskell.org/hoogle/
[2] http://en.wikipedia.org/wiki/Hindley-Milner

-- 
Live well,
~wren


More information about the Haskell-Cafe mailing list