On Dec 17, 2007 8:18 AM, Nicholls, Mark <<a href="mailto:Nicholls.Mark@mtvne.com">Nicholls.Mark@mtvne.com</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The approach is deliberate...but I accept may be harder than it needs to<br>be...I'm interested in Haskell because of the alleged power/formality of<br>it's type system against the relatively weakness of OO ones...the irony
<br>at the moment is that they do not really seem to correspond<br>directly....and OO type system seems to (loosely) correlate to Haskell<br>type class system, and an OO class system (loosely) to Haskels type<br>system, though in OOP's they are unpleasantly tangled.
<br></blockquote></div><br>When I was learning Haskell, I found it helpful to think this way: In an OO system, classes describe objects. In Haskell, classes decribe types.<br><br>It may also be helpful to note that Haskell's class system can be emulated in the language itself[1] by a technique known as "dictionary passing".
<br><br>For example, the Eq class is equivalent to a function of type a -> a -> Bool, for some a.<br><br> type EqD a = a -> a -> Bool<br><br>So any time I have a function that uses Eq,<br><br> foo :: Eq a => a -> a -> a -> a
<br> foo a b c = if a == b then c else b<br><br>I could define an equivalent function without it<br><br> fooBy :: EqD a -> a -> a -> a -> a<br> fooBy eq a b c = if eq a b then c else b<br><br>The difference between foo and fooBy is that fooBy requires me to explicitly provide the Eq dictionary, whereas the compiler takes care of providing it to foo.
<br><br>A lot of functions in Data.List exist in "foo" and "fooBy" forms.<br><br><br>[1] This isn't entirely true if we're talking about Haskell 98. Some classes dictionaries can't be defined without an extension, but that extension is widely supported and will almost certainly be in the next language standard.
<br clear="all"><br>-- <br>Dave Menendez <<a href="mailto:dave@zednenem.com">dave@zednenem.com</a>><br><<a href="http://www.eyrie.org/~zednenem/">http://www.eyrie.org/~zednenem/</a>>