Loading ...
Sorry, an error occurred while loading the content.

4453Re: "ocaml_beginners"::[] Modules

Expand Messages
  • Jon Harrop
    Sep 17, 2005
    • 0 Attachment
      On Sunday 18 September 2005 03:02, Brian Hurt wrote:
      > The golden example of what modules are good for is Set.compare, which
      > needs to ensure you only compare two sets that hold the same type and have
      > the same ordering.

      Yes. More specifically, that is an example of functors, which are part of ML's
      module system.

      > The only valid use I've ever seen for this
      > 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.

      Nowadays, the advantage of unrolling loops comes from optimisations than can
      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 can
      > 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.

      For Java, almost certainly run-time checking.

      > On a more general note, one of the things you need to get used to in Ocaml
      > 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.

      Absolutely. Given the choice, I use modules far more than objects.

      Dr Jon D Harrop, Flying Frog Consultancy Ltd.
      Objective CAML for Scientists
    • Show all 17 messages in this topic