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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id C9B1E7F61E for ; Sun, 5 Nov 2017 21:50:22 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-qt0-f181.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.216.181; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.216.181 as permitted sender) identity=mailfrom; client-ip=209.85.216.181; receiver=mail3-smtp-sop.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 (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qt0-f181.google.com) identity=helo; client-ip=209.85.216.181; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-qt0-f181.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AW86BWhSOCYoIc7+I4knIu4fcNtpsv+yvbD5Q0YIu?= =?us-ascii?q?jvd0So/mwa64ZhGN2/xhgRfzUJnB7Loc0qyN7PCmBDRIyK3CmU5BWaQEbwUCh8?= =?us-ascii?q?QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnY6Uy/yPgtt?= =?us-ascii?q?J+nzBp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hiSE?= =?us-ascii?q?UBR+BFSYEghk0ISVeNYIvCYJEH4F0QDaLEIFVAQEB?= X-IronPort-AV: E=Sophos;i="5.44,349,1505772000"; d="scan'208";a="243490576" Received: from mail-qt0-f181.google.com ([209.85.216.181]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 05 Nov 2017 21:50:21 +0100 Received: by mail-qt0-f181.google.com with SMTP id n61so8734049qte.10 for ; Sun, 05 Nov 2017 12:50:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=JH+ISn4ioez89M+slbCm86D/zyYsIgCW8sR+QwVWatE=; b=awTYWUY6QKcs3i586kgv/LkzrJ/1lR+xEGW3sOh/3SCt/6mGgv4Aub9QqGQu8w64aU QJQMn0AAkPKtmeRFljPz2a9+fnUrH53KCMKT2GvT8OphH8nsWq9/60DYWr1bijKoa+X5 Qy4Osop3D5iN4tugkXxNsELylboX9QnZCv2tDHp9+iSEpulgQe3GRWdpl1hv/uoR3p5L nkPJwhVnp1F0Zbahv/hLbu9jqHt2u3Buv9EoyIVUEMxi16ATW2TgNKaKX0rqPYvW8g3i tKqZb71zD/f5E8dT+ifvKkV1z1N1aYjupJF/FBI2CBUJDMKTH0eQBS58KfXj7WbIMqYY EZxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=JH+ISn4ioez89M+slbCm86D/zyYsIgCW8sR+QwVWatE=; b=tv9RNOTtLtrYp57OHtMkpfhz4bPHAkl9ds/XU8mqkkmPPgDuW0hg0HRn6TDR3B212t wabJwZixNXHEa7KlRjucPVPHZasPQdic8an3HJBgI46x7eBz0Co7Stgrkutso4PKskGE S8OCBCpym15ccRX4Op2a0ibmBRbVO7cTKIyciHWbGoOs7VY1rMoQpfjqPse13d1bMM2x Kb2xeBwxvsp7ubFvFo6ivfkn6OVbcoVXVutzmPt/NRPqeRtnvLGL1Rj0y2QaZHI21i9a ZwsEoTMJKoA4WhiCQMGXwOtVx/82gPPi+gkvBL4DxeCThzPPmhRe4aRo177K3WLyMDEM exqA== X-Gm-Message-State: AMCzsaVyZ4VBZv1gTHRAgGtUaSQp5HI+CfiMrbsYPKzXHus02LT6gmBK vd+7B2A6XAcaDCF9ZU3imO4bF1/TH6hPtzVlEOXMpg== X-Google-Smtp-Source: ABhQp+Tb7HfWUwApwNptBaGJXGe4Utc8+7NCMeBhUJqiBCmBkxxGN5SpYXp++x+LpkgNLeYdjnDFrEHEtEGHPH27vug= X-Received: by 10.237.60.46 with SMTP id t43mr19677897qte.294.1509915020159; Sun, 05 Nov 2017 12:50:20 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.178.65 with HTTP; Sun, 5 Nov 2017 12:49:39 -0800 (PST) In-Reply-To: References: <86o9p2ywgc.fsf@gmail.com> <20171020113815.GD32138@nunchakus.loria.fr> <20171024133026.uovvzdbnamnzoknv@annexia.org> <20171104184401.3el2vbha2tgpvse5@annexia.org> <20171105174116.lbd36diq2xzpjba6@annexia.org> From: Gabriel Scherer Date: Sun, 5 Nov 2017 21:49:39 +0100 Message-ID: To: Yaron Minsky Cc: "Richard W.M. Jones" , octachron , "caml-list@inria.fr" , hugo heuzard Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] What if exn was not an open type? We also have return-by-local-exceptions in Batteries (the BatReturn module), but reports from js_of_ocaml users (namely, Cl=C3=A9ment Pit-Claudel) is that this style gets translated to extremely slow Javascript code -- functions from Batteries using this style (string search functions in particular) were a performance bottleneck on the javascript backend. I fixed the issue by rewriting all uses of BatReturn in Batteries libraries themselves. Long-term, it would be better to have Javascript backends produce better code on this, but I think it is rather difficult -- it is easy to compile efficiently local exceptions that are raised in the same basic block, but with_return takes a callback so you have to both inline and specialize before you are within reach of the optimization. On Sun, Nov 5, 2017 at 7:39 PM, Yaron Minsky wrote: > FWIW, this idiom is supported by Base. > > https://github.com/janestreet/base/blob/master/src/with_return.mli > > I notice we're not yet using the unboxed attribute, though, so we > should fix that... > > y > > On Sun, Nov 5, 2017 at 12:41 PM, Richard W.M. Jones wr= ote: >> On Sat, Nov 04, 2017 at 08:16:17PM +0100, octachron wrote: >>> On 04/11/2017 19:44, Richard W.M. Jones wrote: >>> > The problem is that the return statement could be called from many >>> > contexts, all with different types. The compiler expects to unify all >>> > these types (as the same type 'b) which is not possible. >>> This issue can be solved by making the type of return more precise, >>> capturing the fact that return always raises: >>> >>> type 'a return =3D { return: 'b. 'a -> 'b } [@@unboxed] >>> let with_return (type b) f =3D >>> let exception Return of b in >>> try f {return =3D (fun y -> raise (Return y))} with Return y -> y= ;; >>> >>> It becomes then possible to write >>> >>> let f () =3D >>> with_return (fun {return} -> >>> if false then return "error"; >>> let a =3D >>> match Some "abc" with >>> | None -> return "another error" >>> | Some a -> a in >>> a >>> ) >> >> This one works great, thanks. >> >> Rich. >> >> -- >> Richard Jones >> >> -- >> 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