From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 1B2B47F712 for ; Fri, 24 Jan 2014 00:20:17 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of jon@ffconsultancy.com) identity=pra; client-ip=84.93.230.250; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jon@ffconsultancy.com"; x-sender="jon@ffconsultancy.com"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of jon@ffconsultancy.com) identity=mailfrom; client-ip=84.93.230.250; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jon@ffconsultancy.com"; x-sender="jon@ffconsultancy.com"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@avasout05.plus.net) identity=helo; client-ip=84.93.230.250; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jon@ffconsultancy.com"; x-sender="postmaster@avasout05.plus.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuoCAFyj4VJUXeb6lWdsb2JhbABag0SpUXqSQoERFg4BAQEBBw0JCRIqgiUBAQEDAQgCMDQQBwEDAgkRBAEBAQ0aBxkjCQEJCAIEARILBQKHXwMJDAnBIwOFYBePBwaEMgSPJ4oulBM X-IPAS-Result: AuoCAFyj4VJUXeb6lWdsb2JhbABag0SpUXqSQoERFg4BAQEBBw0JCRIqgiUBAQEDAQgCMDQQBwEDAgkRBAEBAQ0aBxkjCQEJCAIEARILBQKHXwMJDAnBIwOFYBePBwaEMgSPJ4oulBM X-IronPort-AV: E=Sophos;i="4.95,709,1384297200"; d="scan'208";a="54614714" Received: from avasout05.plus.net ([84.93.230.250]) by mail2-smtp-roc.national.inria.fr with ESMTP; 24 Jan 2014 00:20:16 +0100 Received: from XPS ([91.125.112.34]) by avasout05 with smtp id HbLE1n0020kazHn01bLF2U; Thu, 23 Jan 2014 23:20:15 +0000 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=Db0u9JdW c=1 sm=1 tr=0 a=DvnplZMz9B0OTucJM+SM4w==:117 a=DvnplZMz9B0OTucJM+SM4w==:17 a=0Bzu9jTXAAAA:8 a=XCxr5DcLagoA:10 a=Xub9RBUEA-sA:10 a=Kvk-SOs2Z7YA:10 a=kj9zAlcOel0A:10 a=r2vSxAw-AAAA:8 a=BR64nyZ84HQA:10 a=ZOzjf2MOAAAA:8 a=CjxXgO3LAAAA:8 a=GtPC447oVug8GO6PfSAA:9 a=CjuIK1q_8ugA:10 X-AUTH: jdh302:2500 Reply-To: From: "Jon Harrop" To: "'Goswin von Brederlow'" , References: <20140120101654.GI26447@frosties> <08bc01cf17b8$9263d070$b72b7150$@ffconsultancy.com> <20140123092925.GB20624@frosties> In-Reply-To: <20140123092925.GB20624@frosties> Date: Thu, 23 Jan 2014 23:20:23 -0000 Organization: Flying Frog Consultancy Ltd. Message-ID: <01c401cf1891$b1fb1360$15f13a20$@ffconsultancy.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQHI4li4v5YdVc3QG7JLKEaISEVTZQITm23GAs0uvsEBcUwfGALv8TtSmlTcRzA= Content-Language: en-gb Subject: RE: [Caml-list] How much optimized is the 'a option type ? 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