Version française
Home     About     Download     Resources     Contact us    
Browse thread
Typeclasses in OCaml (Was: Haskell vs OCaml)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jim Farrand <jim@f...>
Subject: Typeclasses in OCaml (Was: Haskell vs OCaml)
2008/8/14 Peng Zang <peng.zang@gmail.com>:

> In Haskell you can write a function that takes anything that is "showable" (a
> type class) and print it out.  The sig would be something like (I'm mixing
> OCaml and Haskell syntax here, but hopefully the point is still clear):

Out of curiosity, are there any theoretical reasons why OCaml could
not be extended with type classes?  They are one of my favourite
features of Haskell, and I think they would really improve OCaml.

Things like the (=) operator in OCaml vex me.  One of the big
advantages of static typing and type inference is that stupid
programmer errors are prevented at compile time.  However, the (=)
operator in OCaml is effectively meaningless for a lot of types, yet
there is no way to prevent a programmer from accidentally calling it.

One way to get around this would be to take away (=) and (==) and
replace them with specific versions for each type (just like we already
have (+) and (+.) etc) but this leads to really verbose code.

Type classes solve this kind of problem very effectively.

Regards,
Jim