Goswin wrote:No, Some x is always a reference to a heap-allocated object that contains
> So Some x is the value x unless x is an option type?
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).
Yes. I think it is a bad data representation though. Option types should
> You can't encode 'a option differently depending on 'a unless you have a
flag for which encoding it used as well.
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