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 F062A7EE89 for ; Wed, 25 Oct 2017 11:12:49 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=philippe.veber@gmail.com; spf=Pass smtp.mailfrom=philippe.veber@gmail.com; spf=None smtp.helo=postmaster@mail-oi0-f43.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of philippe.veber@gmail.com) identity=pra; client-ip=209.85.218.43; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of philippe.veber@gmail.com designates 209.85.218.43 as permitted sender) identity=mailfrom; client-ip=209.85.218.43; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@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-oi0-f43.google.com) identity=helo; client-ip=209.85.218.43; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="postmaster@mail-oi0-f43.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3A2ZGG/hftUZ31yA9yk93acSX6lGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxc66Yh7h7PlgxGXEQZ/co6odzbGJ4+a9ASQp2tWojjMrSNR0TRgLiM?= =?us-ascii?q?EbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpRZbIBj0NBJ0?= =?us-ascii?q?K+LpAcaSyp3vj6Hhs6HUNk9yhTG9aKl+ZCrwiEOZlM4QjJAoYvIryxDJinJOfe?= =?us-ascii?q?lGxGouIkicyUXS/MC1qaZj8iBRo+osv/BNW6jgN/AgTb1cDSw+PiYr6cfmrzHM?= =?us-ascii?q?SAKO4j0XVWBAwUkAOBTM8ByvBsS5iSD9rOconXDCZcA=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0DYAABhVPBZfyvaVdFaGwEBAQMBAQEJA?= =?us-ascii?q?QEBFQEBAQECAQEBAQgBAQEBhQYnB4NzgTaYHoF6iTuHPYVCghEKhCYBgRQChGE?= =?us-ascii?q?HQRYBAQEBAQEBAQEBARIBAQkLCwgmMYI4BQEeAQWCOwEBAQMBIwQZARsdAQMBC?= =?us-ascii?q?wYDAgQHDSoCAiIBEQEFARwGE4oHAQMNCItAkRtAjAyBbRgFARyDCQWDaAoZJw1?= =?us-ascii?q?YgmwBAQEBAQEEAQEBAQEbAgYSgxyCB4FQhROIGYJhBaFzgi+SSJMmlW0UBR+BF?= =?us-ascii?q?SYKggI0ISVeNYIvgk2CFD42ikeBVQEBAQ?= X-IPAS-Result: =?us-ascii?q?A0DYAABhVPBZfyvaVdFaGwEBAQMBAQEJAQEBFQEBAQECAQE?= =?us-ascii?q?BAQgBAQEBhQYnB4NzgTaYHoF6iTuHPYVCghEKhCYBgRQChGEHQRYBAQEBAQEBA?= =?us-ascii?q?QEBARIBAQkLCwgmMYI4BQEeAQWCOwEBAQMBIwQZARsdAQMBCwYDAgQHDSoCAiI?= =?us-ascii?q?BEQEFARwGE4oHAQMNCItAkRtAjAyBbRgFARyDCQWDaAoZJw1YgmwBAQEBAQEEA?= =?us-ascii?q?QEBAQEbAgYSgxyCB4FQhROIGYJhBaFzgi+SSJMmlW0UBR+BFSYKggI0ISVeNYI?= =?us-ascii?q?vgk2CFD42ikeBVQEBAQ?= X-IronPort-AV: E=Sophos;i="5.43,431,1503352800"; d="scan'208,217";a="297811377" Received: from mail-oi0-f43.google.com ([209.85.218.43]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 25 Oct 2017 11:12:48 +0200 Received: by mail-oi0-f43.google.com with SMTP id f66so41848546oib.2 for ; Wed, 25 Oct 2017 02:12:48 -0700 (PDT) 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; bh=GegX9H8PrXXtFoosO24lvkE4nzm3vJoSWF4wlbutnZM=; b=fwgN2aVpf3VAZ/w8Xkch27SkIsuWqBzyaqlm1ME/yqyjRXrdlDL19kz1k48tE4vf+9 3Z4AbnqUzJ2OrgpDh++/xqW+UJ+HtIt+t+yWOIwKh4Y00YNyJ/62Xht7amFvKQczxuxi 6gerLcBbzL8QI52wOBt93/tnI9cnqd5XK4XEPia6zptms1ZpYJNhuXRQahDoKdaITb4f kNfbsZQE2aVh3VAv1MFfSpgWPOWvg8YPzrdv9A++OCP/Paks2M9875pOzDstZNhQ8NLg 9vyXAM73A2N28DMqAB055A8/YSrjRyH3iFHgQVNDNIUwTF7dPUMxTo50a7c4+eFalKkB lW2w== 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=GegX9H8PrXXtFoosO24lvkE4nzm3vJoSWF4wlbutnZM=; b=bYZzHQenM09FLADYzDkx1c6BlXkP3AP2tKFQhi4Rlhww2+F78J415DJI0P7UaATzv4 JHqf8rERM7ey3Bzo5aGZ4JeDr2sNZ6AWV9wr6q8SMjAnCvHdw3vKi5blXjiT18+yO2fc wNGDNSiSBRnmaH0aFKJVCPE2uh4vInjKLnexsKxAzQSrm3fMA8JQ+zqMF5vAy9O/0Jyy CeOm0lKXvR4jWRr6C5zMdgqTpPKER9sXHRcvZs1zDrm1qFk6GtlaoS5Wf4Ezdg97GdDa r0G4e/wNawDhyKJF20MwQSSiZ813l6mr06+xoGPajEc6tPKuWn5aVTNM9+fqGxeGi/dB YNbQ== X-Gm-Message-State: AMCzsaXvNfMM6BQMq9Z9Eipw4hlANl3AbjcRJRcZ7uipKiKixSJtEoJ1 wEN5I91FT2c6mtUhYX1CbroZIUn8Q9PQptZdBU4= X-Google-Smtp-Source: ABhQp+RB3cxQulF4/8EFeOKd0GCi9tDj0Mzmv1LrfYrygRCgsO+M1iUIwNq65PddAtL013j5pj4tc3L0QBCVPcOiUfM= X-Received: by 10.202.54.135 with SMTP id d129mr664811oia.31.1508922767255; Wed, 25 Oct 2017 02:12:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.34.138 with HTTP; Wed, 25 Oct 2017 02:12:26 -0700 (PDT) In-Reply-To: <20171025083530.gvggcenrgxolduse@annexia.org> References: <86o9p2ywgc.fsf@gmail.com> <20171020113815.GD32138@nunchakus.loria.fr> <20171024133026.uovvzdbnamnzoknv@annexia.org> <20171025083530.gvggcenrgxolduse@annexia.org> From: Philippe Veber Date: Wed, 25 Oct 2017 11:12:26 +0200 Message-ID: To: "Richard W.M. Jones" Cc: "Petter A. Urkedal" , ptoscano@redhat.com, caml users Content-Type: multipart/alternative; boundary="001a113cf06c892f81055c5b75f8" X-Validation-by: philippe.veber@gmail.com Subject: Re: [Caml-list] What if exn was not an open type? --001a113cf06c892f81055c5b75f8 Content-Type: text/plain; charset="UTF-8" 2017-10-25 10:35 GMT+02:00 Richard W.M. Jones : > On Tue, Oct 24, 2017 at 09:00:05PM +0200, Petter A. Urkedal wrote: > > On 24 October 2017 at 15:30, Richard W.M. Jones > wrote: > > > Since I first used OCaml I have wished for a simple (and type safe) > > > return statement. > > > > It's possible to wrap a bit type (and exception) safety about > > exceptions used for return: > > > > val with_return : (('a -> 'b) -> 'a) -> 'a > > > > let with_return (type b) f = > > let exception Return of b in > > try f (fun y -> raise (Return y)) with Return y -> y > > > > E.g. > > > > with_return (fun return -> List.iter (function 0 -> () | i -> return > > i) [0; 0; 24; 0]; -1);; > > Thanks, that's interesting. > > -- > > As mine was a bit of a "Hit and run" comment, let me expand on > why a return statement is useful for the kind of dull code that > I write. > > I often have to write functions of the form: > > let f () = > if some_problem then ( > printf "sorry, can't do that\n"; > (* return *) > ) > else if some_other_problem then ( > printf "sorry, can't do that either\n"; > (* return *) > ) > else ( > match something with > | None -> > (* return *) > | Some v -> > (* finally we get to do some work! *) > ... > ) > > Hi Richard, isn't that a context where error monads do a pretty decent job? check_some_problem () >>= fun () -> check_some_other_problem () >>= fun () -> expect_something () >>= fun something -> finally_do something Cheers, Philippe. --001a113cf06c892f81055c5b75f8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


2017-10-25 10:35 GMT+02:00 Richard W.M. Jones <rich@annexia.org>= :
On Tue, Oct 24,= 2017 at 09:00:05PM +0200, Petter A. Urkedal wrote:
> On 24 October 2017 at 15:30, Richard W.M. Jones <rich@annexia.org> wrote:
> > Since I first used OCaml I have wished fo= r a simple (and type safe)
> > return statement.
>
> It's possible to wrap a bit type (and exce= ption) safety about
> exceptions used for return:
>
>=C2=A0 =C2=A0val with_return : (('a -> 'b) -> 'a) -&g= t; 'a
>
>=C2=A0 =C2=A0let with_return (type b) f =3D
>=C2=A0 =C2=A0 =C2=A0let exception Return of b in
>=C2=A0 =C2=A0 =C2=A0try f (fun y -> raise (Return y)) with Return y = -> y
>
> E.g.
>
>=C2=A0 =C2=A0with_return (fun return -> List.iter (function 0 -> = () | i -> return
> i) [0; 0; 24; 0]; -1);;

Thanks, that's interesting.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 --

As mine was a bit of a "Hit and run" comment, let me expand on
why a return statement is useful for the kind of dull code that
I write.

I often have to write functions of the form:

=C2=A0 let f () =3D
=C2=A0 =C2=A0 if some_problem then (
=C2=A0 =C2=A0 =C2=A0 printf "sorry, can't do that\n";
=C2=A0 =C2=A0 =C2=A0 (* return *)
=C2=A0 =C2=A0 )
=C2=A0 =C2=A0 else if some_other_problem then (
=C2=A0 =C2=A0 =C2=A0 printf "sorry, can't do that either\n";<= br> =C2=A0 =C2=A0 =C2=A0 (* return *)
=C2=A0 =C2=A0 )
=C2=A0 =C2=A0 else (
=C2=A0 =C2=A0 =C2=A0 match something with
=C2=A0 =C2=A0 =C2=A0 | None ->
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(* return *)
=C2=A0 =C2=A0 =C2=A0 | Some v ->
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(* finally we get to do some work! *)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0...
=C2=A0 =C2=A0 )


Hi Richard,

isn'= t that a context where error monads do a pretty decent job?

check_some_problem () >>=3D fun () ->
check_some_= other_problem () >>=3D fun () ->
expect_something ()= >>=3D fun something ->
finally_do something

=
Cheers,
=C2=A0 Philippe.
=C2=A0
<= /div>
--001a113cf06c892f81055c5b75f8--