From: Xavier Leroy <xavier.leroy@inria.fr>
To: John Prevost <jprevost@libcom.com>
Cc: caml-list@inria.fr, romildo@uber.com.br
Subject: Re: [Caml-list] Function definition with multiple patterns in multiple equations
Date: Fri, 11 Jan 2002 10:23:34 +0100 [thread overview]
Message-ID: <20020111102334.A7963@pauillac.inria.fr> (raw)
In-Reply-To: <20020108082639.A87628@libcom.com>; from jprevost@libcom.com on Tue, Jan 08, 2002 at 08:26:39AM -0500
> Anyway, the quick-n-dirty method of doing multiple patterns like
> your example is to write:
>
> let f a b = match (a,b) with
> | (0, 0) -> 1
> | (_, _) -> 0
>
> But, this may very well have the overhead of actually building a
> pair.
Not in Objective Caml. There's a special optimization in both the
bytecode and native-code compilers to avoid the construction of the
pair in this case.
You can also decompose it into something like:
>
> let f = function
> | 0 -> (function
> | 0 -> 1
> | _ -> 0)
> | _ -> 0
>
> Which is, yes, rather unattractive for such a small example.
That should be:
let f = function
| 0 -> (function
| 0 -> 1
| _ -> 0)
| _ -> (function _ -> 0)
And it would be less efficient due to the extra function invocation
involved. (Assuming f is generally applied to two arguments; if you
do a lot of partial applications of f, the latter might be slightly
more efficient.)
- Xavier Leroy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next prev parent reply other threads:[~2002-01-11 9:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <romildo@uber.com.br>
2002-01-08 13:08 ` José Romildo Malaquias
2002-01-08 13:16 ` Francois Thomasset
2002-01-08 13:18 ` Clement Renard
2002-01-08 13:26 ` John Prevost
2002-01-11 9:23 ` Xavier Leroy [this message]
2002-01-11 9:47 ` Andreas Rossberg
2002-01-08 13:30 ` Remi VANICAT
2002-01-09 13:28 ` [Caml-list] teil recursive function and GC Christophe Raffalli
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=20020111102334.A7963@pauillac.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=caml-list@inria.fr \
--cc=jprevost@libcom.com \
--cc=romildo@uber.com.br \
/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