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 041937F61E for ; Sun, 5 Nov 2017 18:41:18 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=rich@annexia.org; spf=Pass smtp.mailfrom=rich@annexia.org; spf=Pass smtp.helo=postmaster@annexia.org Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of rich@annexia.org) identity=pra; client-ip=80.68.91.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of rich@annexia.org designates 80.68.91.176 as permitted sender) identity=mailfrom; client-ip=80.68.91.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="rich@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@annexia.org designates 80.68.91.176 as permitted sender) identity=helo; client-ip=80.68.91.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="rich@annexia.org"; x-sender="postmaster@annexia.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" IronPort-PHdr: =?us-ascii?q?9a23=3AfHxPfBwAu1fahrbXCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?0u0VIJqq85mqBkHD//Il1AaPBtqLra8cw8Pt8IneGkU4qa6bt34DdJEeHzQksu?= =?us-ascii?q?4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2NBXupSi15iIbERXlMgw9?= =?us-ascii?q?cuP+Bof6l8Ozxuuy/IfUZUNGnmzuT6l1KUD8lwTatsAMjcNdbIN3gjnOpHZTMa?= =?us-ascii?q?wC32JjJXqamRDx9sa5upl5/HID6Loa68dcXPCiLOwDRrtCAWF+Pg=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0D+AgAxTP9Z/7BbRFBcGwEBAQMBAQEJA?= =?us-ascii?q?QEBgzSBUp1cRQaBMZhXCoQmAYEUAoRXQhUBAQEBAQEBAQEBaiiCOCKCRQEFJws?= =?us-ascii?q?BRhALGAkTEg8tGwaKKRGsFTqLBQELJoMuggeBDD2FHYURhXcFmQaJCAKUbZNBl?= =?us-ascii?q?haBOTUigWyBBwhJgmWEXkGMKgEBAQ?= X-IPAS-Result: =?us-ascii?q?A0D+AgAxTP9Z/7BbRFBcGwEBAQMBAQEJAQEBgzSBUp1cRQa?= =?us-ascii?q?BMZhXCoQmAYEUAoRXQhUBAQEBAQEBAQEBaiiCOCKCRQEFJwsBRhALGAkTEg8tG?= =?us-ascii?q?waKKRGsFTqLBQELJoMuggeBDD2FHYURhXcFmQaJCAKUbZNBlhaBOTUigWyBBwh?= =?us-ascii?q?JgmWEXkGMKgEBAQ?= X-IronPort-AV: E=Sophos;i="5.44,348,1505772000"; d="scan'208";a="299380828" Received: from annexia.org ([80.68.91.176]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES256-GCM-SHA384; 05 Nov 2017 18:41:17 +0100 Received: from rich by annexia.org with local (Exim 4.89) (envelope-from ) id 1eBOv6-0008KO-GZ; Sun, 05 Nov 2017 17:41:16 +0000 Date: Sun, 5 Nov 2017 17:41:16 +0000 From: "Richard W.M. Jones" To: octachron Cc: caml-list@inria.fr Message-ID: <20171105174116.lbd36diq2xzpjba6@annexia.org> References: <86o9p2ywgc.fsf@gmail.com> <20171020113815.GD32138@nunchakus.loria.fr> <20171024133026.uovvzdbnamnzoknv@annexia.org> <20171104184401.3el2vbha2tgpvse5@annexia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [Caml-list] What if exn was not an open type? 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