From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id BC6207F719 for ; Fri, 24 Jan 2014 00:29:02 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of yotambarnoy@gmail.com) identity=pra; client-ip=209.85.216.174; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="yotambarnoy@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of yotambarnoy@gmail.com designates 209.85.216.174 as permitted sender) identity=mailfrom; client-ip=209.85.216.174; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="yotambarnoy@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qc0-f174.google.com) identity=helo; client-ip=209.85.216.174; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="postmaster@mail-qc0-f174.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqgEAIWk4VLRVdiulGdsb2JhbABag0RWqHuKaohSgQkIFg4BAQEBBwsLCRIqgiUBAQEDAUABGxILAQMBBwQGBQsGBAEBAQ0aByIBEQEFAQoBCQgGExKHXgEDCQgNnj6MXIMJkjgKGScDCmSEchEBBQyOcAQHBoQyBIlIjluBMo55GCmEdx4 X-IPAS-Result: AqgEAIWk4VLRVdiulGdsb2JhbABag0RWqHuKaohSgQkIFg4BAQEBBwsLCRIqgiUBAQEDAUABGxILAQMBBwQGBQsGBAEBAQ0aByIBEQEFAQoBCQgGExKHXgEDCQgNnj6MXIMJkjgKGScDCmSEchEBBQyOcAQHBoQyBIlIjluBMo55GCmEdx4 X-IronPort-AV: E=Sophos;i="4.95,709,1384297200"; d="scan'208";a="54615286" Received: from mail-qc0-f174.google.com ([209.85.216.174]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 24 Jan 2014 00:29:01 +0100 Received: by mail-qc0-f174.google.com with SMTP id x13so3394644qcv.5 for ; Thu, 23 Jan 2014 15:29:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=T0xKTVAGuVHAWbAhsLIuFA6t/fdqon0eOx/mMUeenM4=; b=UyTxiYa9W9SuJef01FjagmTPMI8ghFZS6caflJGzeyloHd7ZQ/y9HQmax9RduglIbk 4C3eSpoD4ueKXFAGKmMjXb7cwgtQ99xngOSpEhg3wELbosZoGO7HhiC4jEx+eTLs8YDI JkIs9tUtRHKcHlpwFqWqzC8+KEZRX1EVwuOMNRv3pweDAOtm9hxNUYQqw6PEa4r18XLP FxfLNmO1JFJQ/7WZ2iDhnFWj/zBFRwGIOBKfsier99lNwfl+J9ziUPbQJiDE9p/suLLb yvbQ7fgvsrrOGRCRyxcOg75owz7SiE6AQQLjEiao+OXybehUMsbt4DLdk7H+vZb1GKQ4 kIog== X-Received: by 10.140.20.17 with SMTP id 17mr15244631qgi.28.1390519741163; Thu, 23 Jan 2014 15:29:01 -0800 (PST) MIME-Version: 1.0 Received: by 10.224.95.8 with HTTP; Thu, 23 Jan 2014 15:28:40 -0800 (PST) In-Reply-To: <01c401cf1891$b1fb1360$15f13a20$@ffconsultancy.com> References: <20140120101654.GI26447@frosties> <08bc01cf17b8$9263d070$b72b7150$@ffconsultancy.com> <20140123092925.GB20624@frosties> <01c401cf1891$b1fb1360$15f13a20$@ffconsultancy.com> From: Yotam Barnoy Date: Thu, 23 Jan 2014 18:28:40 -0500 Message-ID: To: Jon Harrop Cc: Goswin von Brederlow , Ocaml Mailing List Content-Type: multipart/alternative; boundary=001a11c124f639ca3c04f0ab9b33 Subject: Re: [Caml-list] How much optimized is the 'a option type ? --001a11c124f639ca3c04f0ab9b33 Content-Type: text/plain; charset=ISO-8859-1 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 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 > --001a11c124f639ca3c04f0ab9b33 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Just to clarify, by value types you mean stuff alloca= ted on the stack, right?

-Yotam


On Thu, Jan 23, 2014 at 6:20 PM, J= on 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 cont= ains
the value "x".

In fact, I think it is essentially the same as OCaml's representation f= or
the 'a option type (except for the run-time "type" informatio= n required by
the GC).

> You can't encode 'a option differently depending on 'a unl= ess you have a
flag for which encoding it used as well.

Yes. I think it is a bad data representation though. Option types sho= uld
never allocate anything at all. They should be a value type containing a
boolean "HasValue" and the value itself which has a default in th= e event
that it is None. So None=3D(false, _), Some 3=3D(true, 3), Some None=3D(tru= e,
(false, _)) and Some(Some 3)=3D(true, (true, 3)). You could even store the<= br> Booleans and bytes as pack them so Some(Some 3) would take the same amount<= br> of space (16 bytes) as Some 3.

Cheers,
Jon.

-----Original Message-----
From: caml-list-request@inria= .fr [mailto:caml-list-req= uest@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 nobo= dy
> > 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 = 9;a option
differently depending on 'a unless you have a flag for which encoding i= t
used as well.

I think you can only have one: option types using nil or 'a option opti= on.

Which doesn't mean you can't have nil too, just not to represent th= e None
part of 'a option. In ocaml you would need a new type syntax like

type 'a ptr_option =3D NIL | PTR of 'a constraint type b . 'a != =3D b ptr_option

MfG
=A0 =A0 =A0 =A0 Goswin

--
Caml-list mailing list. =A0Subscription management and archives:
ht= tps://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. =A0Subscription management and archives:
ht= tps://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

--001a11c124f639ca3c04f0ab9b33--