[Haskell-cafe] Re: Newbie question

Brent Yorgey byorgey at gmail.com
Mon Jan 21 12:33:54 EST 2008

2008/1/21 Alexander Seliverstov <seliverstov.a at gmail.com>:

> So, the function type "(Num a)=>Integer->a" means that return value of
> this function can be cast to any particular instance of class Num.
> Ok. I have a my own class "class A a" and want to write function like
> this  "f:: (A a)=>Integer->a". Can I do it?
Only if you make the function f a member of class A.  Then it is the
responsibility of each particular type which is an instance of A to define a
way of converting an Integer into a value of that type.  For example:

class A a where
  f :: Integer -> a
  ... other functions...

instance A Integer where
  f = id

instance A String where
  f = show

and so on.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080121/818936ea/attachment.htm

More information about the Haskell-Cafe mailing list