On Fri, Jan 20, 2012 at 2:29 PM, Edgar Friendly <thelema...@gmail.com> wrote: >> 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 []
Indeed, the four line pattern-matching is turned into two consecutive tests. In many cases, the pattern-matching compiler only generates the optimal number of tests, so never be scared of creating big complex patterns... Regards, Fabrice -- 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