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

michael rice nowgate at yahoo.com
Fri May 29 00:11:59 EDT 2009


And I thought everyone was puzzling these type signatures out all by themselves. ;-)

The Haskell learning curve is about the steepest I've ever seen for a computer language, but I think I'm catching on.

Thanks for the info.

Michael


--- On Thu, 5/28/09, wren ng thornton <wren at freegeek.org> wrote:

From: wren ng thornton <wren at freegeek.org>
Subject: Re: [Haskell-cafe] What's the problem with iota's type signature?
To: "Haskell-cafe" <haskell-cafe at haskell.org>
Date: Thursday, May 28, 2009, 11:14 PM

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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090528/2c669028/attachment.html


More information about the Haskell-Cafe mailing list