
Thanks. I get it.
2008/1/21, Jon Fairbairn
"Alexander Seliverstov"
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 you
f:: (A a) => Integer -> a f n = undefined
:-P
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@cl.cam.ac.uk
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- С уважением, Селиверстов Александр