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 99C417EC6E for ; Fri, 17 Jan 2014 14:57:09 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of frederic.bour@lakaban.net) identity=pra; client-ip=94.23.239.155; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="frederic.bour@lakaban.net"; x-sender="frederic.bour@lakaban.net"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of frederic.bour@lakaban.net designates 94.23.239.155 as permitted sender) identity=mailfrom; client-ip=94.23.239.155; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="frederic.bour@lakaban.net"; x-sender="frederic.bour@lakaban.net"; 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.lakaban.net) identity=helo; client-ip=94.23.239.155; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="frederic.bour@lakaban.net"; x-sender="postmaster@mail.lakaban.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqAEAJFf2FJeF++b/2dsb2JhbABZvyqBJXSCJQEBAQMBMgEFCAEBNgIECwsYCRYPCQMCAQIBRQYBDAgBAYd4DKgqhFIBBZg7EQaPBoQ4AZQ+iiyLUYMu X-IPAS-Result: AqAEAJFf2FJeF++b/2dsb2JhbABZvyqBJXSCJQEBAQMBMgEFCAEBNgIECwsYCRYPCQMCAQIBRQYBDAgBAYd4DKgqhFIBBZg7EQaPBoQ4AZQ+iiyLUYMu X-IronPort-AV: E=Sophos;i="4.95,670,1384297200"; d="scan'208";a="53717526" Received: from lakaban.net (HELO mail.lakaban.net) ([94.23.239.155]) by mail2-smtp-roc.national.inria.fr with ESMTP; 17 Jan 2014 14:57:09 +0100 Received: from [192.168.1.20] (unknown [78.206.197.34]) (Authenticated sender: defre@ygg-drasil.fr) by mail.lakaban.net (Postfix) with ESMTPSA id 637D11200980; Fri, 17 Jan 2014 14:55:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=lakaban.net; s=default; t=1389966906; bh=CgS6gv34X1CuN+bhBvBkeIGjgIhKiiMxAwh2oh6uk7U=; h=Message-ID:Date:From:MIME-Version:To:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=s4+a4I9gkGheUustFQQuZs+UIl7UE/9M8WcBWcJgSQWxcQuQgOwWRYei04Tgcf1Ck bamlAdvh/xGF65kpb56oLe9c1X1EQnSI5zzQ0mjCFNHudct6yEmLr87lIHtVARZGAG HZPVMShLwkXPVYuh146JJcdvyxSE2Klk4qxSZJPs= Message-ID: <52D9367C.3050703@lakaban.net> Date: Fri, 17 Jan 2014 14:56:12 +0100 From: =?windows-1252?Q?Fr=E9d=E9ric_Bour?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Nicolas Braud-Santoni , caml-list@inria.fr References: <52D9342B.30704@gmail.com> In-Reply-To: <52D9342B.30704@gmail.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] How much optimized is the 'a option type ? Le 17/01/2014 14:46, Nicolas Braud-Santoni a écrit : > 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 ? This won't work when used with 'a = another type with constant constructors. And what about 'a 'a t? Sticking to a uniform representation prevents a lot of problem. > Kind regards, > Nicolas