[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jon Harrop <jon@f...> |
| Subject: | Re: [Caml-list] Polymorphic Variants |
On Wednesday 17 January 2007 21:13, Tom wrote: > Any comments? Yes: I prefer things the way they are. You can add overloading to ML but you must then add lots of type annotations to your code. For example, vector length: let length (x, y) = sqrt(x*.x +. y*.y) becomes: let length (x : float, y : float) = sqrt(x*x + y*y) So you've saved the "." three times at the cost of ": float" twice because the overloaded * and + don't provide enough type information. You can complicate the type inferer to counteract this but then other type errors will become increasingly obscure and the programmer will be forced to learn the quirks that you've added in order to debug their code. Constructor overloading can be done in OCaml using polymorphic variants. They are slower. Code written in this style quickly becomes unmaintainable because the type errors (from inference) are so complicated that you are forced to annotate types. Finally, I don't want my types discovered at run-time because it makes my code slower and uses more memory. I'd rather have to box manually, so fast code is concise code. From my point of view, your suggestions are mostly steps backwards (towards Lisp, C++ etc.). I think the best way to improve OCaml is to write an IDE that sidesteps these problems, e.g. by typesetting the code "+." as "+". -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists