caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques GARRIGUE <garrigue@kurims.kyoto-u.ac.jp>
To: j.prevost@gmail.com
Cc: bhurt@spnz.org, caml-list@inria.fr
Subject: Re: [Caml-list] Unboxing options, was RE: assertions or exceptions?
Date: Fri, 16 Jul 2004 09:35:17 +0900 (JST)	[thread overview]
Message-ID: <20040716.093517.95470327.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <d849ad2a0407151020725c3fb9@mail.gmail.com>

From: John Prevost <j.prevost@gmail.com>

> On Thu, 15 Jul 2004 10:38:14 -0500 (CDT), Brian Hurt <bhurt@spnz.org> wrote:
> > One of the problems with returning error conditions instead of throwing
> > exceptions is the cost of boxing a 'a option.  I'd like to advocate for
> > the idea of unboxing 'a options.
> 
> This has been discussed before.  The essential problem is this:
> 
> Currently:
> 
> type 'a option is not the same as type 'a option option
> Some Some 1 is not the same as Some 1
> Some None is not the same as None
> 
> With unboxed options:
> 
> type 'a option is the same as type 'a option option
> Some Some 1 is identical to Some 1
> Some None is identical to None

I answer before the discussion goes hairy (it already has.)

We know perfectly how to unbox options. This is described for instance
in my paper with Jun Furuse on optional arguments.
  http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/papers/rims-1041.html

The idea is just to reserve a sufficiently large memory area to
represent every needed (Some (Some ...(Some None) ...)).
You don't even need to access this area (it might not be physically
mapped.)
Then all values of type (t option) are represented either by a pointer
to this area, or by the wrapped value itself (if it is not an option.)

I believe Xavier implemented this trick once, but this has some small
cost for both wrapping and unwrapping (you must check whether the
value is a pointer to this area), so that there is no clear
advantage compared to allocating a block for each Some. Keep in mind
that most options are short-lived, so they will be allocated in the
young generation, and disappear with the next GC. Such a pattern has a
very low cost: just check the allocation limit once in a while. And of
course there is no cost for the None case.

Conclusion: this is not worth bothering about, and optional
implemented in the current way are efficient enough, thank you.

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2004-07-16  0:35 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-15  8:03 [Caml-list] " Radu Grigore
2004-07-15 10:18 ` Richard Jones
2004-07-15 10:28   ` Daniel Andor
2004-07-15 12:49   ` Radu Grigore
2004-07-15 13:33     ` Richard Jones
2004-07-15 13:58       ` Radu Grigore
2004-07-16 18:53         ` Aleksey Nogin
2004-07-17  2:55           ` John Prevost
2004-07-17 14:24             ` David MENTRE
2004-07-15 12:35 ` Jon Harrop
2004-07-15 13:45   ` Radu Grigore
2004-07-15 14:33     ` Jon Harrop
2004-07-15 15:05       ` Radu Grigore
2004-07-15 16:24     ` skaller
2004-07-15 15:38 ` [Caml-list] Unboxing options, was " Brian Hurt
2004-07-15 16:25   ` John Hughes
2004-07-15 17:00     ` Brian Hurt
2004-07-15 17:20   ` John Prevost
2004-07-15 19:14     ` Radu Grigore
2004-07-15 19:56     ` John Carr
2004-07-15 20:48       ` Brian Hurt
2004-07-15 20:49         ` John Carr
2004-07-15 21:15           ` John Prevost
2004-07-15 21:15           ` Karl Zilles
2004-07-15 21:26           ` Brian Hurt
2004-07-15 21:04       ` John Prevost
2004-07-15 21:17     ` skaller
2004-07-15 21:35       ` Brian Hurt
2004-07-15 21:51         ` skaller
2004-07-15 21:42       ` skaller
2004-07-16  0:35     ` Jacques GARRIGUE [this message]
2004-07-16  1:03       ` John Prevost
2004-07-16  2:00         ` Jacques GARRIGUE
2004-07-16 16:40         ` Xavier Leroy
2004-07-19  8:58           ` Damien Doligez

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=20040716.093517.95470327.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=bhurt@spnz.org \
    --cc=caml-list@inria.fr \
    --cc=j.prevost@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).