On 01/20/2012 03:37 AM, David Allsopp wrote:
Actually, it's possible that with more cases it might be faster -
it's
eliminating the allocation (at some point) of all the tuples needed for
the match case,

Doesn't the ocaml compiler not allocate the unnecessary tuples? https://ocaml.janestreet.com/?q=node/90

it potentially eliminates a lot of linear comparisons to
find the correct match case (I don't think that the compiler would be
able to optimise that to a hash-based or index-based lookup)

Isn't the compiler's compilation strategy for match cases able to build an optimized tree of comparisons in cases like this? I agree there's no easy index or hash strategy for this, but I'd expect it to turn this pattern matching into the equivalent of:

if a then if b then [a;b] else [a]
else if b then [b] else []

E.

--
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to