4453Re: "ocaml_beginners":: Modules
- Sep 17, 2005On Sunday 18 September 2005 03:02, Brian Hurt wrote:
> The golden example of what modules are good for is Set.compare, whichYes. More specifically, that is an example of functors, which are part of ML's
> needs to ensure you only compare two sets that hold the same type and have
> the same ordering.
> The only valid use I've ever seen for thisNowadays, the advantage of unrolling loops comes from optimisations than can
> feature is vectors and matricies. But even there I disagree that it's
> that big of an advantage. Unrolling loops is of signifigantly less value
> on modern superscalar, out of order, speculatively executing CPUs. Loop
> branching is highly predictable and therefor pretty much free.
be applied to the unrolled code, rather than diminishing the cost of the
branch. Several bits of the OCaml stdlib have been manually unrolled and this
gives a significant performance boost.
> Another thing modules are good for- changing algebras for your algorithms.I'm currently using functors to derive progressively more specialised types of
balanced binary tree.
> For real fun, try to write a Set.compare function that the compiler canFor Java, almost certainly run-time checking.
> catch that you're comparing two sets of different types of objects, or two
> sets with different orderings. You can do it with C++ templates,
> signifigantly less cleanly and with all of the standard problems C++
> templates bring with them (massive code bloat, etc.). I'm not sure what
> the solution to that problem in Java or Python is.
> On a more general note, one of the things you need to get used to in OcamlAbsolutely. Given the choice, I use modules far more than objects.
> is the lack of golden hammers. The classic example of a golden hammer in
> language design is objects- the assumption that everything should be
> objects. Ocaml has a surprising lack of golden hammers, and a plethora of
> different, more specialized tools. It has both modules and objects.
> Because sometimes it's better to use objects, and sometimes it's better to
> use modules. And sometimes you use both.
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
- << Previous post in topic Next post in topic >>