caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yotam Barnoy <yotambarnoy@gmail.com>
To: Jon Harrop <jon@ffconsultancy.com>
Cc: Goswin von Brederlow <goswin-v-b@web.de>,
	Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] How much optimized is the 'a option type ?
Date: Thu, 23 Jan 2014 18:28:40 -0500	[thread overview]
Message-ID: <CAN6ygO=4xFdK692LXZmtSB-aQTgVqGuxARHgi3UvD1XOV2Bseg@mail.gmail.com> (raw)
In-Reply-To: <01c401cf1891$b1fb1360$15f13a20$@ffconsultancy.com>

[-- Attachment #1: Type: text/plain, Size: 2775 bytes --]

Just to clarify, by value types you mean stuff allocated on the stack,
right?

-Yotam


On Thu, Jan 23, 2014 at 6:20 PM, Jon Harrop <jon@ffconsultancy.com> wrote:

> Goswin wrote:
> > So Some x is the value x unless x is an option type?
>
> No, Some x is always a reference to a heap-allocated object that contains
> the value "x".
>
> In fact, I think it is essentially the same as OCaml's representation for
> the 'a option type (except for the run-time "type" information required by
> the GC).
>
> > You can't encode 'a option differently depending on 'a unless you have a
> flag for which encoding it used as well.
>
> Yes. I think it is a bad data representation though. Option types should
> never allocate anything at all. They should be a value type containing a
> boolean "HasValue" and the value itself which has a default in the event
> that it is None. So None=(false, _), Some 3=(true, 3), Some None=(true,
> (false, _)) and Some(Some 3)=(true, (true, 3)). You could even store the
> Booleans and bytes as pack them so Some(Some 3) would take the same amount
> of space (16 bytes) as Some 3.
>
> Cheers,
> Jon.
>
> -----Original Message-----
> From: caml-list-request@inria.fr [mailto:caml-list-request@inria.fr] On
> Behalf Of Goswin von Brederlow
> Sent: 23 January 2014 09:29
> To: caml-list@inria.fr
> Subject: Re: [Caml-list] How much optimized is the 'a option type ?
>
> On Wed, Jan 22, 2014 at 09:26:09PM -0000, Jon Harrop wrote:
> > Goswin wrote:
> > > In F#, with nil pointer, that will be a problem. But I guess nobody
> > > ever
> > has 'a option option types there
> >
> > I believe the representation of Some None in F# is a heap allocated
> > block containing a NULL pointer.
> >
> > Cheers,
> > Jon.
>
> So Some x is the value x unless x is an option type? That wouldn't work for
> polymorphic functions, those taking 'a option. You can't encode 'a option
> differently depending on 'a unless you have a flag for which encoding it
> used as well.
>
> I think you can only have one: option types using nil or 'a option option.
>
> Which doesn't mean you can't have nil too, just not to represent the None
> part of 'a option. In ocaml you would need a new type syntax like
>
> type 'a ptr_option = NIL | PTR of 'a constraint type b . 'a != b ptr_option
>
> MfG
>         Goswin
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 4192 bytes --]

  reply	other threads:[~2014-01-23 23:29 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-17  7:35 Damien Guichard
2014-01-17  7:55 ` David House
2014-01-17  8:16   ` Julien Blond
2014-01-17  8:40     ` David House
2014-01-17  9:10       ` Gabriel Scherer
2014-01-17  9:22         ` Simon Cruanes
2014-01-17 17:57           ` Gerd Stolpmann
2014-01-18  1:35             ` Jon Harrop
2014-01-19  6:19               ` oleg
2014-01-21  1:51                 ` Francois Berenger
2014-01-18  1:01         ` Jon Harrop
2014-01-24 10:06         ` Alain Frisch
2014-01-24 10:16           ` Alain Frisch
2014-01-24 13:32             ` Yaron Minsky
     [not found]       ` <CAK=fH+jfi=GsMYBZzmuo=V5UAWimyxiiamY2+DkLg6F0i8XHGw@mail.gmail.com>
2014-01-17  9:11         ` David House
2014-01-17 11:23           ` Jonathan Kimmitt
2014-01-17 13:46             ` Nicolas Braud-Santoni
2014-01-17 13:56               ` Frédéric Bour
2014-01-17 14:02               ` Yaron Minsky
2014-01-17 14:09                 ` Simon Cruanes
2014-01-17 22:52                   ` Yaron Minsky
2014-01-18  1:37                   ` Jon Harrop
2014-01-17 14:24                 ` Gabriel Scherer
2014-01-17 22:29                   ` Yaron Minsky
2014-01-18  1:27                 ` Jon Harrop
2014-01-18  1:18             ` Jon Harrop
2014-01-20 10:16             ` Goswin von Brederlow
2014-01-20 11:23               ` Jonathan Kimmitt
2014-01-21  2:05                 ` Francois Berenger
2014-01-22 21:22                   ` Jon Harrop
2014-01-22 21:26               ` Jon Harrop
2014-01-23  9:29                 ` Goswin von Brederlow
2014-01-23 23:20                   ` Jon Harrop
2014-01-23 23:28                     ` Yotam Barnoy [this message]
2014-01-24  8:22                       ` Jon Harrop
2014-01-24  8:34                         ` Andreas Rossberg
2014-01-24 16:56                           ` Jon Harrop
2014-01-27 15:29                             ` Goswin von Brederlow
2014-01-27 16:18                               ` Yotam Barnoy
2014-01-29  7:56                                 ` Goswin von Brederlow
2014-01-29  8:32                                 ` Jon Harrop
2014-01-29 16:11                                   ` Yotam Barnoy
2014-01-30 18:43                                     ` Yotam Barnoy
2014-02-01 15:58                                       ` Goswin von Brederlow
2014-01-30 21:31                                     ` Jon Harrop
2014-01-30 21:43                                       ` Yotam Barnoy
2014-01-31  8:26                                         ` Jon Harrop
2014-02-01 15:40                                 ` Goswin von Brederlow
2014-01-27 10:03                         ` Goswin von Brederlow
2014-01-17 14:36 ` Markus Mottl
2014-01-17 15:49   ` Yotam Barnoy
2014-01-17 16:22     ` Markus Mottl
2014-01-20 10:09   ` Goswin von Brederlow

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='CAN6ygO=4xFdK692LXZmtSB-aQTgVqGuxARHgi3UvD1XOV2Bseg@mail.gmail.com' \
    --to=yotambarnoy@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    --cc=jon@ffconsultancy.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).