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 0BECC7EE5B for ; Mon, 26 May 2014 17:13:28 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of bmillwood@janestreet.com) identity=pra; client-ip=38.105.200.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="bmillwood@janestreet.com"; x-sender="bmillwood@janestreet.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of bmillwood@janestreet.com designates 38.105.200.115 as permitted sender) identity=mailfrom; client-ip=38.105.200.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="bmillwood@janestreet.com"; x-sender="bmillwood@janestreet.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@mxout1.mail.janestreet.com) identity=helo; client-ip=38.105.200.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="bmillwood@janestreet.com"; x-sender="postmaster@mxout1.mail.janestreet.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmcBAE1Zg1MmachznGdsb2JhbABZg1lYgmqqWZROAYEKHg4BAQEBAQYWCTyCJgEBBBIRBBkBATcBDwsEAQY3AgIiEgEFARwGNYggAwIIo0pqijB3hH8BBaBZEQIEjk4EB4J1gUuZd5E2GCmEaQ X-IPAS-Result: AmcBAE1Zg1MmachznGdsb2JhbABZg1lYgmqqWZROAYEKHg4BAQEBAQYWCTyCJgEBBBIRBBkBATcBDwsEAQY3AgIiEgEFARwGNYggAwIIo0pqijB3hH8BBaBZEQIEjk4EB4J1gUuZd5E2GCmEaQ X-IronPort-AV: E=Sophos;i="4.98,913,1392159600"; d="scan'208";a="76444134" Received: from mxout2.mail.janestreet.com (HELO mxout1.mail.janestreet.com) ([38.105.200.115]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 26 May 2014 17:13:27 +0200 Received: from tot-smtp.delacy.com ([172.27.22.15] helo=tot-smtp) by mxout1.mail.janestreet.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.82) (envelope-from ) id 1Wowab-0001Vx-P4 for caml-list@inria.fr; Mon, 26 May 2014 11:13:25 -0400 Received: from tot-dmz-mxgoog1.delacy.com ([172.27.224.14] helo=mxgoog2.janestreet.com) by tot-smtp with esmtps (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1Wowab-0008NU-MJ for caml-list@inria.fr; Mon, 26 May 2014 11:13:25 -0400 Received: from mail-qc0-f179.google.com ([209.85.216.179]) by mxgoog2.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1Wowab-0005X7-KQ for caml-list@inria.fr; Mon, 26 May 2014 11:13:25 -0400 Received: by mail-qc0-f179.google.com with SMTP id r5so3860258qcx.10 for ; Mon, 26 May 2014 08:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=6M9i8QqyUB1vM5ZpHZ4Y4pkOjl9Y6dET9UefDuDV3EQ=; b=ROqUZsAMnlqKDXEjIftlGPT7qNEqxeAXTRcxGnnK6+1Q0IuKSrsn8ZKJ8eSQxyByXd vkkWiWq9QfxTPwMt4oZQ9fUIuLjR+EhD+f1YtuNfh49pT600lWCeUSebMAdlTkzqCgfG UHyWsSL0qEdihW+t/IZb6PsJeetVXXCEtAmss= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=6M9i8QqyUB1vM5ZpHZ4Y4pkOjl9Y6dET9UefDuDV3EQ=; b=jRAtnUsTz1TCz0UzHYYjjZFkjkSV4IiPNb4r6u3T1FTrhLOaxJn0QgdPScHS7Alv/u 03wXpo1RwQk5eARZSo/5yrCcsmWTqOr9uCyWgl/A9EHj313WS3YOtGwVzlqH3/ZHIqm0 8W6LO/r/XxbZBJdOenOGvszahlXVHvZMjK/R42Q3W22AhcKhsn6oxsEABzm+PK8a/tTp lcxJCVsNHlsEP08xalpGkbmzCO00rdc3hJSa+8JDC58+c/ImDQ3+3ICC22xlV3i8SlAW nDviwhsSVEj+x6HIHUbCPPaa5BQrz6B/25QYqEX+CJKE04hYshnBENgQT/hwjcElgMMS x7zA== X-Gm-Message-State: ALoCoQmqYn67wiemWniDksDB6B/JD7kgypZZEd5ZmNleMVHNcv1nFuGX3V8L9qT9at3JVmBYGm70SGpRE3iBmrIaIicOAG/m3hhWI0ro79K4XZ3/PDJJp57cf1+BOaKndGvk7ynbBOw1 X-Received: by 10.140.36.105 with SMTP id o96mr31345639qgo.25.1401117205468; Mon, 26 May 2014 08:13:25 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.140.36.105 with SMTP id o96mr31345626qgo.25.1401117205365; Mon, 26 May 2014 08:13:25 -0700 (PDT) Received: by 10.140.103.67 with HTTP; Mon, 26 May 2014 08:13:25 -0700 (PDT) In-Reply-To: <53835610.9050609@inria.fr> References: <53835610.9050609@inria.fr> Date: Mon, 26 May 2014 16:13:25 +0100 Message-ID: From: Ben Millwood To: Romain Bardou Cc: caml users Content-Type: multipart/alternative; boundary=001a11c1733450d40a04fa4f05cb Subject: Re: [Caml-list] Uncaught exceptions in function type. --001a11c1733450d40a04fa4f05cb Content-Type: text/plain; charset=UTF-8 First of all, it seems to be universal among all languages I've much experience with that there are unchecked exceptions. Your program might be interrupted at any point by an out of memory error or a signal or something, and there's just not much you can do about that. You can either model it in your code or not, but you can't stop it from happening. So it seems like the best we can hope for with typed exceptions is in addition to unchecked ones, to make it possible (but not required) that a function might declare some of the exceptions it can throw. But after all exceptions are just "things I can return instead of a result", and lightweight sum types are already pretty good at that. E.g. (to use Romain's syntax) val lookup : map -> key -> value raise Not_found is pretty much just the same as: val lookup : map -> key -> value option True, exceptions get automatic propagation, but the option monad interface makes that pretty lightweight, and you can do a similar thing with a less trivial sum type if you need richer type information. See also: https://blogs.janestreet.com/how-to-fail-introducing-or-error-dot-t/ for discussions of more ways you can make error handling both explicit and concise. --001a11c1733450d40a04fa4f05cb Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
First of all, it seems to be universal among all languages= I've much experience with that there are unchecked exceptions. Your pr= ogram might be interrupted at any point by an out of memory error or a sign= al or something, and there's just not much you can do about that. You c= an either model it in your code or not, but you can't stop it from happ= ening. So it seems like the best we can hope for with typed exceptions is i= n addition to unchecked ones, to make it possible (but not required) that a= function might declare some of the exceptions it can throw.

But after all exceptions are just "things I can re= turn instead of a result", and lightweight sum types are already prett= y good at that. E.g. (to use Romain's syntax)

=C2=A0= =C2=A0=C2=A0 val lookup : map -> key -> value raise Not_found

is pretty much just the same as:

=C2=A0=C2= =A0=C2=A0 val lookup : map -> key -> value option

T= rue, exceptions get automatic propagation, but the option monad interface m= akes that pretty lightweight, and you can do a similar thing with a less tr= ivial sum type if you need richer type information.

See also: https://blogs.janestreet.com/how-to-fail-int= roducing-or-error-dot-t/ for discussions of more ways you can make erro= r handling both explicit and concise.
--001a11c1733450d40a04fa4f05cb--