4 ms·
I'm considering OCaml for a new project where C++ would be the typical choice. Think algorithms handling massive amounts of data, and some numerics. I have som
by nextos 11y ago
I'm considering OCaml for a new project where C++ would be the typical choice. Think algorithms handling massive amounts of data, and some numerics.
I have some experience with ML, Haskell & Lisp. OCaml is appealing because it is quite efficient and predictable. Does it have the bit of laziness Clojure has that makes functional programming easy with large data?
- shriphani 11y agoFunction application in OCaml is eager. However, implementing laziness is trivially accomplished.
- raphaelss 11y agoIt already comes with support for lazy evaluation. http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec216 http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec216
- sgeisenh 11y agoJust about every eagerly evaluated functional language supports laziness through thunks. This is just syntactic sugar.
- gmfawcett 11y agoYes, there is support for laziness (see "streams"). A couple things to keep in mind: floating point values in Ocaml are boxed (floats are actually pointers to float data on the heap), and integers are one bit shorter than native types (31 or 63 bits) due to the way that Ocaml values are tagged internally. The native compiler generates good, predictable, but fairly simple code: few optimizations are applied (although there is active work underway, in the "flambda" project, that will significantly change this). Also, there is of course a garbage collector, though it is quite efficient in most cases. These factors may or may not be a performance issue in your own project.
- DonPellegrino 11y agoIn practice the generated code is already extremely fast and the 1-bit shorter ints help make the GC one of the fastest I've seen. If you do a lot of floating point calculations, you can put your floats in an array and they'll become unboxed.