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

Francesco Bochicchio bieffe62 at gmail.com
Fri Jan 23 08:51:17 EST 2009


2009/1/23 Jan Jakubuv <jakubuv at gmail.com>

> hi,
>
> 2009/1/23 Francesco Bochicchio <bieffe62 at gmail.com>:
> >
> > Then I discovered that this piece of code  (1) is illegal in askell (ghc
> > gives the 'rigid type variable' error)
> >
> > Num n => a :: n
> > a = 3 :: Integer
> >
>
> I guess you mean:
>
> a :: Num n => n
>

Yes. I'm not _that_ beginner  :-) (although I tend to make this mistake
quite often ).


>
> The problem whith your implementation of 'a'
>
> a = 3 :: Integer
>
> is that it provides too specific result. Its type signature says that
> its result has to be of the type n for *any* instance of the class
> Num. But your result is simply Integer that is just *one* specific
> instance of Num. In other words it has to be possible to specialize
> ("retype") 'a' to any other instance of Num, which is no longer
> possible because (3 :: Integer) is already specialized.
>

Uhm. Now I think I start to get it ...
You are saying that if a value is a Num, it shall be possible to convert it
in _any_ of the num instances?





> Sincerely,
>  jan.
>


Ciao
-------
FB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090123/38a72072/attachment-0001.htm


More information about the Beginners mailing list