[Haskell-cafe] Newbie question

Alexander Seliverstov seliverstov.a at gmail.com
Mon Jan 21 11:36:18 EST 2008

How does caller choose which particular instance of Num they want?

In object-oriented language If function return type is an interface it means
that it can return any implementation of this interface, but caller can't
choose which particular inplementation they want.

What the difference between haskell class and interface in object-oriented
languge such Java or C#?

2008/1/21, Brent Yorgey <byorgey at gmail.com>:
> 2008/1/21 Alexander Seliverstov <seliverstov.a at gmail.com>:
> > Hi, I try to undestand why this code dosen't work
> >
> > f :: (Num a)=>Integer->a
> >
> > f i = i
> >
> > Integer is an instance of Num, so why does this code produce error:
> > "Couldn't  match expected type 'a' againsta inferred type 'Integer' ..."
> >
> But the type of this function says that it can return *any* instance of
> Num -- that is, the caller gets to choose which particular instance of Num
> they want.  This function can only ever return an Integer.
> There is actually a function of this type, however; it's called
> fromIntegral.  It works because it is a member of the Num type class.
> -Brent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080121/34585218/attachment.htm

More information about the Haskell-Cafe mailing list