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 DF6D57F61E for ; Sun, 5 Nov 2017 19:40:10 +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@mxout1.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.78; 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.78 as permitted sender) identity=mailfrom; client-ip=38.105.200.78; 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@mxout1.mail.janestreet.com) identity=helo; client-ip=38.105.200.78; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="postmaster@mxout1.mail.janestreet.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3A6WaKLhcN5F3HMyVXgoAWYQKvlGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxc64ZR7h7PlgxGXEQZ/co6odzbGJ4+a9ASQp2tWojjMrSNR0TRgLiM?= =?us-ascii?q?EbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpRZbIBj0NBJ0?= =?us-ascii?q?K+LpAcaSyp3vj6HhzabOeB1FjyaRZrZ7LRP+7VmA95pevYw3YJwwwRvAuHcARK?= =?us-ascii?q?JzgytKIlSehFy0st2x955L+iJWtuIg/ohHS6qsLIoiSrkNPT08NGZ9wcztrhrS?= =?us-ascii?q?BV+e43oaSWYHuhhBBQXe8Av3U4u3uSz/4LkukBKGNNH7GOhnEQ+p6L1mHVq10S?= =?us-ascii?q?o=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0B4AABwWv9ZfU7IaSZcGgEBAQECAQEBA?= =?us-ascii?q?QgBAQEBhBhuJweDdoofjxmBfIJTk3OCEQojhAMBgRQChFAHPxgBAQEBAQEBAQE?= =?us-ascii?q?BEgEBCRYIV4I4BQEeBoI9AQIDIwQZAQEsCwEPCwsNAgIJHQICIhIBBQEKEgYTE?= =?us-ascii?q?ol5AxUDDZ09QIsha4FtOoMJAQEFhCIDg1ABAQEBAQEBAQEBAQEBAQEBAQEBFwg?= =?us-ascii?q?SfYIfggeBU4FpgyqDFgyFBIJiiEMMiiePHYdmh02FSYIyQokEhzyMYYkhFAUfg?= =?us-ascii?q?RUfgiQ0IQgdFUk1BoIpCYJEgjBZih+BVQEBAQ?= X-IPAS-Result: =?us-ascii?q?A0B4AABwWv9ZfU7IaSZcGgEBAQECAQEBAQgBAQEBhBhuJwe?= =?us-ascii?q?DdoofjxmBfIJTk3OCEQojhAMBgRQChFAHPxgBAQEBAQEBAQEBEgEBCRYIV4I4B?= =?us-ascii?q?QEeBoI9AQIDIwQZAQEsCwEPCwsNAgIJHQICIhIBBQEKEgYTEol5AxUDDZ09QIs?= =?us-ascii?q?ha4FtOoMJAQEFhCIDg1ABAQEBAQEBAQEBAQEBAQEBAQEBFwgSfYIfggeBU4Fpg?= =?us-ascii?q?yqDFgyFBIJiiEMMiiePHYdmh02FSYIyQokEhzyMYYkhFAUfgRUfgiQ0IQgdFUk?= =?us-ascii?q?1BoIpCYJEgjBZih+BVQEBAQ?= X-IronPort-AV: E=Sophos;i="5.44,348,1505772000"; d="scan'208";a="243483836" Received: from mxout1.mail.janestreet.com ([38.105.200.78]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2017 19:40:09 +0100 Received: from [172.27.56.106] (helo=tot-qpr-mailcore2) by mxout1.mail.janestreet.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eBPq4-0005dN-GU for caml-list@inria.fr; Sun, 05 Nov 2017 13:40:08 -0500 X-JS-Flow: external X-JS-Scanner-attachment: (ok) No attachments Received: by tot-qpr-mailcore2 with ocaml/mailcore/mailcore 1.0+137 (04e1cd915edc) (envelope-from ) id BZ_1sI-0KrsnA-O9; 2017-11-05 13:40:08.482207-05:00 Received: from mail-vk0-f72.google.com ([209.85.213.72]) by mxgoog1.mail.janestreet.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89) (envelope-from ) id 1eBPq4-0006wZ-EU for caml-list@inria.fr; Sun, 05 Nov 2017 13:40:08 -0500 Received: by mail-vk0-f72.google.com with SMTP id j2so3611018vki.15 for ; Sun, 05 Nov 2017 10:40:08 -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; bh=WdSOA8pKueWoohoMpav2SM0LPGza+9nPvNkRiD9Axfo=; b=2S2b6OCkpCZLYcSVTWMmazQsn0zKcqoWpXXwZF7UtPODFB57xidFCSjufJJnABNHFd kgPEEyUexeBKa8Dc3y402/hcEhVuOx5C5PdBhyZni31GJEyBtRrxwQDnVGkzGuJ2gtLS +ND1E7u2m0qtALVhtOzTMh2FquSrlReXULFI4= 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; bh=WdSOA8pKueWoohoMpav2SM0LPGza+9nPvNkRiD9Axfo=; b=Qc1cXq+CFOx0m2WY5ZAFCtwvW/mwxVEEWhV3NZ2FWcl/s2zaADm+5ineA5o71gkcz8 LdUPNPOyJrYMLTD9BBOAyYSQ7aYeF+LT3RsrtJSeKiUt9h0AreqyLW45yZW+b49E8OEW nMGezyOx9ig6X2OdYUzEIZJAFKmK0q3He4TFESBIxhwvdI0fIetuGGaZ2LG+UBw8bEgV LYcyXtbY9Y/T63gaHl1vc6bd56yhVCq0wgDgW+ERSOYTU2LSD+SV56QEU4DEcllDZgNf N+ODMDthpUiWw7rAyB+SDIftc5Pv9xIrwYjE309mya3DxQgvyVEu4p/HwwDuW2zlEoqL GP4Q== X-Gm-Message-State: AMCzsaUnBNCY3g7eNyGS0ZZ9aZKKjzcun3cgvysTGGlOlENwNwnOv/wa v6/OaZXYDMOUDPAeUOJBAM45jlmc8cUGam+iohRmdSLsV0o8YD2LDjhSi2+UFiqv1VP/J6AGLPF 47ffLwBrT8dij8ylWbTe9cgIQeg== X-Received: by 10.176.78.209 with SMTP id x17mr9752935uah.113.1509907207830; Sun, 05 Nov 2017 10:40:07 -0800 (PST) X-Google-Smtp-Source: ABhQp+TfT3B/ZF0Mx/Hl73JL9EQNHFL3jIcKvfqAEOM/PwIgBzEHSk/eg+Pksd4OBcHbXSrOPcaHF4o11dGDaQ4ixXw= X-Received: by 10.176.78.209 with SMTP id x17mr9752915uah.113.1509907207274; Sun, 05 Nov 2017 10:40:07 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.85.92 with HTTP; Sun, 5 Nov 2017 10:39:46 -0800 (PST) In-Reply-To: <20171105174116.lbd36diq2xzpjba6@annexia.org> 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 13:39:46 -0500 Message-ID: To: "Richard W.M. Jones" Cc: octachron , "caml-list@inria.fr" Content-Type: text/plain; charset="UTF-8" X-JS-Exim-Data-Received: 2017-11-05 13:40:08-0500 X-JS-Processed-by: mailcore Subject: Re: [Caml-list] What if exn was not an open type? 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 wrote: > 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 = { return: 'b. 'a -> 'b } [@@unboxed] >> let with_return (type b) f = >> let exception Return of b in >> try f {return = (fun y -> raise (Return y))} with Return y -> y;; >> >> It becomes then possible to write >> >> let f () = >> with_return (fun {return} -> >> if false then return "error"; >> let a = >> 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