Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Gabriel Kerneis <kerneis@pps.jussieu.fr>
To: William <r.3@libertysurf.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] caml match optimization
Date: Wed, 17 Oct 2012 00:14:00 +0200	[thread overview]
Message-ID: <20121016221400.GX26417@kerneis.info> (raw)
In-Reply-To: <507DD785.8030300@libertysurf.fr>

On Tue, Oct 16, 2012 at 11:54:13PM +0200, William wrote:
> let apply2 = function
> | `Foo -> apply_all_elements foo foo_struct
> | `Bar -> apply_all_elements bar bar_struct
> | `Baz -> apply_all_elements baz baz_struct
> [...]
> | `Biz -> apply_all_elements biz biz_struct
> 
> 
> How much is "apply2" inefficient ?

Efficiency notwithstanding (and I wouldn't expect much of the OCaml compiler in
this area), I'd find the code cleaner with a Map m from `Foo to (foo,
foo_struct), `Bar to (bar, bar_struct), etc., then:
let apply2 x = let (f,s) = Map.find x m in apply_all_elements f s

Best,
-- 
Gabriel

  reply	other threads:[~2012-10-16 22:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-16 21:54 William
2012-10-16 22:14 ` Gabriel Kerneis [this message]
2012-10-16 22:17 ` Gabriel Scherer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121016221400.GX26417@kerneis.info \
    --to=kerneis@pps.jussieu.fr \
    --cc=caml-list@inria.fr \
    --cc=r.3@libertysurf.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox