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 1E7D07EC6E for ; Sat, 18 Jan 2014 02:27:31 +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.244; 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.244; 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@avasout03.plus.net) identity=helo; client-ip=84.93.230.244; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="jon@ffconsultancy.com"; x-sender="postmaster@avasout03.plus.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AugCAOLX2VJUXeb0lWdsb2JhbABZg0OpF3qRbIEMFg4BAQEBBw0JCRIqgiUBAQEECAIwNAsMAQMCCQ4DBAEBAQ0aBxkIGwkBCQgCBAESCwUCCYdWAxUJvicDCoVWF4xrghQHBoQyBI8lhRaBeoMdiyuIaA X-IPAS-Result: AugCAOLX2VJUXeb0lWdsb2JhbABZg0OpF3qRbIEMFg4BAQEBBw0JCRIqgiUBAQEECAIwNAsMAQMCCQ4DBAEBAQ0aBxkIGwkBCQgCBAESCwUCCYdWAxUJvicDCoVWF4xrghQHBoQyBI8lhRaBeoMdiyuIaA X-IronPort-AV: E=Sophos;i="4.95,677,1384297200"; d="scan'208";a="53789666" Received: from avasout03.plus.net ([84.93.230.244]) by mail2-smtp-roc.national.inria.fr with ESMTP; 18 Jan 2014 02:27:30 +0100 Received: from XPS ([91.125.229.6]) by avasout03 with smtp id FDTV1n00108vflX01DTWZm; Sat, 18 Jan 2014 01:27:30 +0000 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=VqIaXYGn c=1 sm=1 tr=0 a=YNNwqyIk8JSiwARLj6s6Lw==:117 a=YNNwqyIk8JSiwARLj6s6Lw==: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=pGLkceISAAAA:8 a=ZOzjf2MOAAAA:8 a=CjxXgO3LAAAA:8 a=m6F-l1E-ilsf2lb3e4kA:9 a=ZFwzo5cM-SsWeYHR:21 a=DHsZIfqC2u5xMp_k:21 a=CjuIK1q_8ugA:10 a=MSl-tDqOz04A:10 X-AUTH: jdh302:2500 Reply-To: From: "Jon Harrop" To: "'Yaron Minsky'" , "'Nicolas Braud-Santoni'" Cc: References: <52D9342B.30704@gmail.com> In-Reply-To: Date: Sat, 18 Jan 2014 01:27:31 -0000 Organization: Flying Frog Consultancy Ltd. Message-ID: <02dc01cf13ec$75d38600$617a9200$@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: AQITm23GUPanAma4/sJij0gkqtCZnwDSPG6bAiNfOa+Z6OrI4A== Content-Language: en-gb Subject: RE: [Caml-list] How much optimized is the 'a option type ? What if you unbox locals and box only when a value is written into the heap? Consider your type: type ('a,'b) result = | Ok of 'a | Error of 'b The representation could be a bit tag, an 'a and a 'b. These three would be passed into a function as three separate arguments etc. In essence, the representation is the value type bit * 'a * 'b while the value is local (a function parameter, a local variable, a return value) and the usual boxed representation when it is written into the heap. I actually wanted to try implementing this representation in HLVM... Cheers, Jon. -----Original Message----- From: caml-list-request@inria.fr [mailto:caml-list-request@inria.fr] On Behalf Of Yaron Minsky Sent: 17 January 2014 14:02 To: Nicolas Braud-Santoni Cc: caml-list@inria.fr Subject: Re: [Caml-list] How much optimized is the 'a option type ? I also agree with Gabriel that an option-specific optimization is not clearly the right move. But I wonder if a more general optimization that provided the possibility of minting "fast-path" variants. i.e., one could have an annotation that marked a given branch of a variant as the "no-indirection" one, i.e., the one that doesn't lead to the allocation of an extra block: type ('a,'b) result = | Ok of 'a [@@no_indirection] | Error of 'b would lead to a type where [Ok x == x]. Some cleverness is required then for the representation of the [Error] branch. In particular, you'd need some dynamic test you could run to see if you were using a value that was not the fast-path one. The thing that I don't know if there's a solution for is the nesting problem. i.e., can you effectively distinguish: Ok (Ok (Error x)) from Error x since they would have the same physical representation. I'm not sure if some variant of the counting trick used for options would work here or not. But if you could get this, it would make it possible to avoid a large number of dirty Obj.magic hacks that people need to do to build efficient datastructures in practice. The fact that the stdlib needs to use Obj.magic to get the necessary performance is, I think, a sign that something important is missing from the language. I'm not sure if this is quite it, to be clear. y On Fri, Jan 17, 2014 at 8:46 AM, Nicolas Braud-Santoni wrote: > On 17/01/2014 12:23, Jonathan Kimmitt wrote: >> In my humble opinion the main purpose of Some _ | None is to avoid >> the requirement for a nil pointer in OCaml. If an external function >> wants to return nil in order to indicate, for example that a certain >> resource is not available, it can return None instead and this >> prevents dereferencing a nil pointer in OCaml because the None cannot be dereferenced. > Yes. > This doesn't forbid the compiler from representing 'a option values as > pointers. > Indeed, the type system already enforces that the None case is handled > and the representation of None and Some _ do not matter. > > That said, I agree with Gabriel Scherer : adding optimizations > specific to 'a option might refrain people wanting to switch to more > appropriate datatypes. > However, would is be possible to "optimize away" all types of the form > "type 'a t = X of 'a | A | B | ..." (with at most one non-constant > constructor) ? > Would it be worth doing ? > > > Kind regards, > Nicolas > -- 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=