-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 14 August 2008 10:46:41 am Jim Farrand wrote:
> 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
>

- From what I was told earlier on this list, if you want type classes in OCaml 
you go with objects.  So you would not have:

  (=) : 'a -> 'a -> bool

But instead:

  (=) : (#equatable as 'a) -> 'a -> bool

where

  class type equatable = object
    method equals : 'self -> bool
  end


This gives all the advantages of static typing and type inference and prevents 
stupid errors and it is meaningful for all types that it is implemented for.


Peng
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFIpE11fIRcEFL/JewRAmyEAKCIbPDMFVh+zuCQ5uD/t+FNPXRJ2gCgwTTl
ZELl4dYgZvnh8cAhlnN2gb0=
=7pTp
-----END PGP SIGNATURE-----

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to