[Haskell-beginners] Re: Type classes are not like interfaces, after all

Eric Macaulay eeoam at ukfsn.org
Sat Jan 24 08:28:41 EST 2009


Francesco Bochicchio <bieffe62 <at> gmail.com> writes:

>
> It worked well ... unitil yesterday. Then I discovered that this piece
> of code (1) is illegal in askell (ghc gives the 'rigid type variable'
> error)

> a :: Num n => n
> a = 3 :: Integer 

A way to understand the type of a is that it has an implicit parameter:

a :: {n:Type} -> Num n -> n

Now we can see why the definition you gave doesn't work - the type n is
provided by the caller of your function which *must* return a value of
that type. If your function was called with

a {Float} _ 0.0

then you must return a Float. Your definition specifically declares you
return an integer, which is wrong.

Hope this helps,
Eric



More information about the Beginners mailing list