caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Typeclasses in OCaml (Was: Haskell vs OCaml)
@ 2008-08-14 14:46 Jim Farrand
  2008-08-14 15:21 ` [Caml-list] " Peng Zang
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jim Farrand @ 2008-08-14 14:46 UTC (permalink / raw)
  To: Caml Mailing List

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-08-15 11:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-14 14:46 Typeclasses in OCaml (Was: Haskell vs OCaml) Jim Farrand
2008-08-14 15:21 ` [Caml-list] " Peng Zang
2008-08-14 15:38   ` Jon Harrop
2008-08-14 16:04   ` Jim Farrand
2008-08-14 17:13     ` Peng Zang
2008-08-14 18:37     ` Till Varoquaux
2008-08-15 11:03       ` Wolfgang Lux
2008-08-14 20:53 ` Nathaniel Gray
2008-08-14 22:33   ` Erik de Castro Lopo
2008-08-15  0:21 ` Brian Hurt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).