[Haskell-cafe] Re: Newbie question
seliverstov.a at gmail.com
Mon Jan 21 14:09:33 EST 2008
Thanks. I get it.
2008/1/21, Jon Fairbairn <jon.fairbairn at cl.cam.ac.uk>:
> "Alexander Seliverstov" <seliverstov.a at gmail.com> writes:
> > 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.
> For some meanings of the word "cast" yes. I'd rather say
> "f:: Num a=> Integer -> a" means that for any type a that is
> an instance of Num, given an integer f will return a member
> of that type.
> > 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?
> You need to be a bit more specific about what f is supposed
> to do without that, I can answer unequivocally yes, and give
> f:: (A a) => Integer -> a
> f n = undefined
> But in general you are going to want something a bit more
> useful, which means that you have to have a path from
> Integer to a -- what the path can be is depends on what
> "methods" you give class A. For example:
> class A a where
> first_a :: a
> second_a :: a
> f :: A t => Integer -> t
> f n | odd n = first_a
> | otherwise = second_a
> J¨®n Fairbairn Jon.Fairbairn at cl.cam.ac.uk
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe