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 9E5987F61E for ; Sun, 5 Nov 2017 22:48:33 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=yminsky@janestreet.com; spf=Pass smtp.mailfrom=yminsky@janestreet.com; spf=None smtp.helo=postmaster@mxout3.mail.janestreet.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of yminsky@janestreet.com) identity=pra; client-ip=38.105.200.229; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="yminsky@janestreet.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of yminsky@janestreet.com designates 38.105.200.229 as permitted sender) identity=mailfrom; client-ip=38.105.200.229; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="yminsky@janestreet.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@mxout3.mail.janestreet.com) identity=helo; client-ip=38.105.200.229; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="postmaster@mxout3.mail.janestreet.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AKy2wEBBLXtRUikndh58qUyQJP3N1i/DPJgcQr6Af?= =?us-ascii?q?oPdwSP75osbcNUDSrc9gkEXOFd2Crakb26yL6+jJYi8p39WoiDg6aptCVhsI24?= =?us-ascii?q?09vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6lX71zMZGw3+OAxp?= =?us-ascii?q?Pay1X9eK14Xk4duv4IXeaBlkgz+0YLU6bEnn7FaZis5DroJoMKc8zlPyqXtFYe?= =?us-ascii?q?lMjTdnLFiJnhv4oNy7/JN5/j54tPco9soGWqL/KfcWV7tdWQUvKWczrOjqswLA?= =?us-ascii?q?XEPb934dVH4VgzJKCg7I9w3gU5rt9CD9s7wui2GhIcTqQOVsCnyZ5KBxRUqt1X?= =?us-ascii?q?4K?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0DBAADbhf9ZfeXIaSZcGQEBAQEBAQEBA?= =?us-ascii?q?QEBBwEBAQEBhBhuJweDdpk4gXyCU4V+kAYKI4QDAYEUAoRQB0MUAQEBAQEBAQE?= =?us-ascii?q?BARIBAQkWCFeCOAUBHgaCPQECAyMEGQEBLAsBDwsLDQICCR0CAiEBEgEFAQoSB?= =?us-ascii?q?hMSiXkDFQMNnSVAiyFrgW06gwkBAQWEIwMKg0YBAQEBAQEBAQEBAQEBAQEBAQE?= =?us-ascii?q?BFwgSfYIfggeBU4Fpgh2BDYJqLAyBLkGDFYJiiEMMiieOYTyHZodNUIR5gjJCi?= =?us-ascii?q?QSHPIxhOYhoFAUfgRU2gg00IQgdFUk1BoIpCYJEgjBZixCBVQEBAQ?= X-IPAS-Result: =?us-ascii?q?A0DBAADbhf9ZfeXIaSZcGQEBAQEBAQEBAQEBBwEBAQEBhBh?= =?us-ascii?q?uJweDdpk4gXyCU4V+kAYKI4QDAYEUAoRQB0MUAQEBAQEBAQEBARIBAQkWCFeCO?= =?us-ascii?q?AUBHgaCPQECAyMEGQEBLAsBDwsLDQICCR0CAiEBEgEFAQoSBhMSiXkDFQMNnSV?= =?us-ascii?q?AiyFrgW06gwkBAQWEIwMKg0YBAQEBAQEBAQEBAQEBAQEBAQEBFwgSfYIfggeBU?= =?us-ascii?q?4Fpgh2BDYJqLAyBLkGDFYJiiEMMiieOYTyHZodNUIR5gjJCiQSHPIxhOYhoFAU?= =?us-ascii?q?fgRU2gg00IQgdFUk1BoIpCYJEgjBZixCBVQEBAQ?= X-IronPort-AV: E=Sophos;i="5.44,349,1505772000"; d="scan'208";a="243492748" Received: from mxout3.mail.janestreet.com ([38.105.200.229]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2017 22:48:32 +0100 Received: from [172.27.56.68] (helo=tot-qpr-mailcore1) by mxout3.mail.janestreet.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eBSmN-0001Oq-1H for caml-list@inria.fr; Sun, 05 Nov 2017 16:48:31 -0500 X-JS-Flow: external X-JS-Scanner-attachment: (ok) No attachments Received: by tot-qpr-mailcore1 with ocaml/mailcore/mailcore 1.0+136 (04e1cd915edc) (envelope-from ) id BZ_4cu-FdUSQA-e8; 2017-11-05 16:48:30.994919-05:00 Received: from mail-vk0-f71.google.com ([209.85.213.71]) by mxgoog1.mail.janestreet.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) (envelope-from ) id 1eBSmM-0001ln-U5 for caml-list@inria.fr; Sun, 05 Nov 2017 16:48:30 -0500 Received: by mail-vk0-f71.google.com with SMTP id g11so3695782vkd.12 for ; Sun, 05 Nov 2017 13:48:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=6mNx6Y58qecp6DqqkdGdvjt7bbI83Hc2OHq3qNhJ/UI=; b=Ek4iOTPmIKvsB9jmAFxdlRUvMuYf/EbaskWqkEUnUiRebLvPg7xYQDFV4HMcrfSegD FK94bWRRfe+ihMGZqc/HnBvGmgcYXKQ8VIGN6HiFli16z3/vZJwzFAIAqoxyQ2ziXkFi tPynku8SytBiHYt4GokBomGCwaiflk9yHaQdA= 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=6mNx6Y58qecp6DqqkdGdvjt7bbI83Hc2OHq3qNhJ/UI=; b=fA3TDJ2FBRAWJ6mtjEyzHQ6TEUZVfkbi/oR30XT8Seu2hOnwubyymi71cRzoisStS6 IJ2iOg+RJhL2bB9vCVI/OFXo1L+Nva70YF+keMYAH0hbIjrxWGLXlHcJjMVR02SBrZtf iqJKvoqctkjyYFFJKgPMYmzq52CoiUDMpA7ZEXbTt8T9wkaM6BQ+IbS7TNo79hF07bvc 1oLL+/SJx09+UZsUDI3z5dhDCnlWwE6laZ9wn/O2D0QP0a1lrrTOmaDOZXRkJqv69CSf 7oGoC6cDnwXPrBQLrVexDPbJZh3lEoMxiE/51daecglmehW0vTzO0nM7+3hxXwN5Ny67 SaHQ== X-Gm-Message-State: AJaThX7uc2WEAy6d+huMJyDDXsklHgHiCrG4NxZJ9EGrz37biiJcTFkT s1ZvkN7OuhDykE1B1btA0MeMFgG0F7YTq1WjxH+SercXFkyic9XdLVt+yPuQJJBT7Y9mnDCsH7O fuAcRMLViK0H9xXgN9upL3QH5sw== X-Received: by 10.176.70.97 with SMTP id z33mr4892603uab.107.1509918510359; Sun, 05 Nov 2017 13:48:30 -0800 (PST) X-Google-Smtp-Source: ABhQp+TNXsN8otpoT3rvX2XEv7FpSK66KorBBWutjHyvPbrEiHDBmA8QdxI1Mm0UIZHFv02uHBH69yBSDlYFq0G8fuU= X-Received: by 10.176.70.97 with SMTP id z33mr4892588uab.107.1509918509929; Sun, 05 Nov 2017 13:48:29 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.85.92 with HTTP; Sun, 5 Nov 2017 13:48:09 -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: Yaron Minsky Date: Sun, 5 Nov 2017 16:48:09 -0500 Message-ID: To: Gabriel Scherer Cc: "Richard W.M. Jones" , octachron , "caml-list@inria.fr" , hugo heuzard Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-JS-Exim-Data-Received: 2017-11-05 16:48:30-0500 X-JS-Processed-by: mailcore Subject: Re: [Caml-list] What if exn was not an open type? Yeah, this is a general problem with exception-catching idioms. We rand into effectively the same issue with respect to the Base's Map and Set implementations, which are rather slow on JavaScript. We haven't rewritten those to a more efficient style yet, though. y On Sun, Nov 5, 2017 at 3:49 PM, Gabriel Scherer wrote: > 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 wro= te: >> 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 w= rote: >>> 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 a= ll >>>> > 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