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 99FE07EC6E for ; Fri, 17 Jan 2014 15:25:24 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.214.44; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.214.44 as permitted sender) identity=mailfrom; client-ip=209.85.214.44; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@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-bk0-f44.google.com) identity=helo; client-ip=209.85.214.44; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-bk0-f44.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqABAJFf2FLRVdYsm2dsb2JhbABZg0NWqCiSaYEHCBYOAQEBAQEGCwsJFCiCJQEBAQMBQAEbEgsBAwELBgULAwoNISEBAREBBQEKEgYTEgmHVAEDCQgNnQ6MXIMJkhQKGScDCmSEchEBBQyMX4FhMweEOASUO4F6gWyBMYsrg04YKYRaOw X-IPAS-Result: AqABAJFf2FLRVdYsm2dsb2JhbABZg0NWqCiSaYEHCBYOAQEBAQEGCwsJFCiCJQEBAQMBQAEbEgsBAwELBgULAwoNISEBAREBBQEKEgYTEgmHVAEDCQgNnQ6MXIMJkhQKGScDCmSEchEBBQyMX4FhMweEOASUO4F6gWyBMYsrg04YKYRaOw X-IronPort-AV: E=Sophos;i="4.95,670,1384297200"; d="scan'208";a="53723318" Received: from mail-bk0-f44.google.com ([209.85.214.44]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 17 Jan 2014 15:25:24 +0100 Received: by mail-bk0-f44.google.com with SMTP id ej10so1662283bkb.17 for ; Fri, 17 Jan 2014 06:25:23 -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:content-transfer-encoding; bh=xx9AIXaIq4WYYC8rNMdOObzpvUxcDSdCMZmmMSNzSHM=; b=eKAzV64uXF3Tv23SiRi6MeCFMOGnSLe0ri8X5oYwcN8/QfJUjPHYZs+kH0xnZwsS8Y FltxBaqBzrynlUPnh/9DPw+vJFQnCebkdKIRbL+SqRblIuT0KopVfI6iQV8fR1EL1Obm XAq9pf6Bp+M/2VbGoDQ0NAeprPQtd3qLiUx5sfhsmQAEv5XnT+MpGTqeP0KtnhJT6jRs T8lY23yGgZn9k3rLtP1mTYU+zDxvngV5yxb9i29H5+HXAWo6XUEiugmUgUmYoI96gAcB 9R9L91KfkaZ2RGNJyNYFhGOpWZ/tJ/xb/8vmWzSXBhN0pse1BJhLNSLBftp3pyeePB2i Fw3w== X-Received: by 10.204.106.139 with SMTP id x11mr1299175bko.7.1389968723547; Fri, 17 Jan 2014 06:25:23 -0800 (PST) MIME-Version: 1.0 Received: by 10.205.45.5 with HTTP; Fri, 17 Jan 2014 06:24:43 -0800 (PST) In-Reply-To: References: <52D9342B.30704@gmail.com> From: Gabriel Scherer Date: Fri, 17 Jan 2014 15:24:43 +0100 Message-ID: To: Yaron Minsky Cc: Nicolas Braud-Santoni , "caml-list@inria.fr" Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] How much optimized is the 'a option type ? > 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 think this specific example needs to die. Yes, there is an Obj.magic in the implementation of Queue, and this mistake was committed more than a decade ago. But we could perfectly remove this use of Obj.magic and use different implementation techniques to get equally efficient (or better) code. But there is no reason to change code that works well enough. That some Obj.magic remains in some old code is *no excuse* to use it today or tomorrow. On Fri, Jan 17, 2014 at 3:02 PM, Yaron Minsky wrot= e: > 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 =3D > | Ok of 'a [@@no_indirection] > | Error of 'b > > would lead to a type where [Ok x =3D=3D 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 =93optimize away=94 all types of the fo= rm >> =93type 'a t =3D X of 'a | A | B | ...=94 (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