
-----Original Message----- From: Bulat Ziganshin [mailto:bulat.ziganshin@gmail.com] Sent: 10 January 2008 13:36 To: Nicholls, Mark Cc: Luke Palmer; haskell-cafe@haskell.org Subject: Re[2]: [Haskell-cafe] confusion about 'instance'....
Hello Mark,
Thursday, January 10, 2008, 4:25:20 PM, you wrote:
"instance Num a =>> A a"
Mean the same thing as
"instance A (forall a.Num a=>a)"
programmers going from OOP world always forget that classes in Haskell doesn't the same as classes in C++. *implementation* of this instance require to pass dictionary of Num class along with type. now imagine the following code:
My confusion is not between OO classes and Haskell classes, but exactly are the members of a Haskell type class...I'd naively believed them to be types (like it says on the packet!)...but now I'm not so sure.
f :: A a => a -> a
f cannot use your instance because it doesn't receive Num dictionary of type `a`. it is unlike OOP situation where every object carries the generic VMT which includes methods for every class/interface that object supports
as usual, i suggest you to study http://haskell.org/haskellwiki/OOP_vs_type_classes first and especially two papers mentioned in References there
I have done....learning is not an atomic operation....i.e. I can only believe what I understand...academic papers are especially beyond me at this point. I can translate OO into mathematical logic pretty easily, I was trying to do the same thing (informally of course) with Haskell....but things are not quite what they appear....not because of some OO hang up (which I probably have many)...but because of what "type class" actually means. So you may be right, I think I need to understand more about the sematics of Haskell...I was hoping to stay (initially) ignorant. I will try the postscript doc and see if it makes any sense.
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com