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 CCF4D80211 for ; Sat, 21 Oct 2017 23:28:21 +0200 (CEST) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=nathanjmoreau@gmail.com; spf=Pass smtp.mailfrom=nathanjmoreau@gmail.com; spf=None smtp.helo=postmaster@mail-io0-f176.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of nathanjmoreau@gmail.com) identity=pra; client-ip=209.85.223.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="nathanjmoreau@gmail.com"; x-sender="nathanjmoreau@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of nathanjmoreau@gmail.com designates 209.85.223.176 as permitted sender) identity=mailfrom; client-ip=209.85.223.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="nathanjmoreau@gmail.com"; x-sender="nathanjmoreau@gmail.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@mail-io0-f176.google.com) identity=helo; client-ip=209.85.223.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="nathanjmoreau@gmail.com"; x-sender="postmaster@mail-io0-f176.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AW4ly6hKMylCDLLpvLdmcpTZWNBhigK39O0sv0rFi?= =?us-ascii?q?tYgUK/TxwZ3uMQTl6Ol3ixeRBMOAtKIC1rKempujcFJDyK7JiGoFfp1IWk1Nou?= =?us-ascii?q?QttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBX660e/5j8KGxj5KRE9?= =?us-ascii?q?ZqGsQtaT3PKMyvuq9pbPTwJNjTu7KfMufVTl5TnW4+wfhYBlLqN57xLVq39Lcq?= =?us-ascii?q?wCwGZhOVuXnB/U6cK5/Zol+CNV7aEP7clFBIPzY6QxS/R9Cy4rOn19sMviqRnK?= =?us-ascii?q?S02K4WERW3g+l0ZYRQ/f40epDd/KriLmu78li2GhNsrsQOVxBG2v?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0DhAACWuutZhrDfVdFcGwEBAQMBAQEJA?= =?us-ascii?q?QEBFQEBAQECAQEBAQgBAQEBhBhuJweDc5ldgXqCUYV6kAkjhAMBhUsHQxQBAQE?= =?us-ascii?q?BAQEBAQEBARIBAQEICwsIKC+COAUBHgaCPAEFIwQZAS0LAQMMAQUFCwMKAgIJH?= =?us-ascii?q?QICIQESAQUBChIGExIHiW8DFRCeGUCMDIFtOoMJBYN6JwMKhAMCBhJ9gh+CB4F?= =?us-ascii?q?QhROCXoU7gmEFiDcMmGc8gi+FNYgXhHmCcpAvjQyIXBQFH4EVNoF8NCEyUTUGg?= =?us-ascii?q?ikJeYFLDgEcgWk+NokOgVUBAQE?= X-IPAS-Result: =?us-ascii?q?A0DhAACWuutZhrDfVdFcGwEBAQMBAQEJAQEBFQEBAQECAQE?= =?us-ascii?q?BAQgBAQEBhBhuJweDc5ldgXqCUYV6kAkjhAMBhUsHQxQBAQEBAQEBAQEBARIBA?= =?us-ascii?q?QEICwsIKC+COAUBHgaCPAEFIwQZAS0LAQMMAQUFCwMKAgIJHQICIQESAQUBChI?= =?us-ascii?q?GExIHiW8DFRCeGUCMDIFtOoMJBYN6JwMKhAMCBhJ9gh+CB4FQhROCXoU7gmEFi?= =?us-ascii?q?DcMmGc8gi+FNYgXhHmCcpAvjQyIXBQFH4EVNoF8NCEyUTUGgikJeYFLDgEcgWk?= =?us-ascii?q?+NokOgVUBAQE?= X-IronPort-AV: E=Sophos;i="5.43,413,1503352800"; d="scan'208";a="241894384" Received: from mail-io0-f176.google.com ([209.85.223.176]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 21 Oct 2017 23:28:20 +0200 Received: by mail-io0-f176.google.com with SMTP id m81so16508506ioi.13 for ; Sat, 21 Oct 2017 14:28:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=sQRRJnwqMBt1cInh3ju2oyKKh96pbjgbmdnttfdP5xw=; b=rTU+lpTSxSiX5QwdNHhkisTQck4jKhCwvQD4XjI02h9s8Lqy/Oyz5CzvJwPFubDnJo 2yknW6M5oOresu5HWIYsuMO/CcNiIwe3cHlJ5NELNGZvhGvaUKrl3VoaHavWv0yxiAAt QaRtd0SbWgeSDA4MRA+JOH44qG3dv8IshHfkbrLs9RCXRRurPY9bP6H5ZEomPXrc/f/b Gj0BP7/2dnOni3LvaGtToKJzlytlcoh7gU+bHM3Y1Dn2XrNLnZ6QsrN9dxlFx4r/NC4F 3DDZkI3uWfxsNe7G/x24YGBOwIueTCTifFxEY0a9QNTD75VAm7StNerYyL1BYNOSJsBy EsSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=sQRRJnwqMBt1cInh3ju2oyKKh96pbjgbmdnttfdP5xw=; b=V3QkmuDgQpCec5B3cMyUMbO8N8kY/IF6DFkXZaba/8kqGr489CJNF0CXMvvEuyJ1rc SMklCprTzmX+E2pAxz5Gn3aR3tPj5fBZW3sunMGHgXmIpFVoXa1CGS73VBgMgE+cfmuq Eo7uzI2Zr6ERE3YzfochB35TmA7kf/HBOchhj9e90rjfXRXDV3uz50QL2yWtOdmzK7oT vinCsh0ONiTMS4h4ELIyAxmA4MpBFhlZt04yEN3MNeD3SmlcyFdDADD682zjLwnLJT6q nWzttLZkOyc4SnoKNPlnEJmKRiT0D6+DN5IB+EL2AYMwj2BIB5t80rGjIKKInt0y8JjS O4gA== X-Gm-Message-State: AMCzsaWTp9YaFHAuW0knE71HLe+hFO80N9MH9yrqaf7qFKegz+OlPB+X Y9zCsbsYE2iWhoAo3A8R6U7JkBREInsjD2D2bB8= X-Google-Smtp-Source: ABhQp+Rxf8goJSRf9u5EuxoQFM6tWTfRL3YkwleDUJSUekGC3NH8CpGxfTckSQ7UE5/5IEIuEjVD8Z5hMJdDMTRAr38= X-Received: by 10.107.162.7 with SMTP id l7mr11057444ioe.135.1508621299290; Sat, 21 Oct 2017 14:28:19 -0700 (PDT) MIME-Version: 1.0 Sender: nathanjmoreau@gmail.com Received: by 10.2.146.195 with HTTP; Sat, 21 Oct 2017 14:28:18 -0700 (PDT) In-Reply-To: <86o9p2ywgc.fsf@gmail.com> References: <86o9p2ywgc.fsf@gmail.com> From: Nathan Moreau Date: Sat, 21 Oct 2017 23:28:18 +0200 X-Google-Sender-Auth: 6hVp4HzoCoyugVIyWy1MV70mt_4 Message-ID: To: Malcolm Matalka Cc: caml users Content-Type: text/plain; charset="UTF-8" Subject: Re: [Caml-list] What if exn was not an open type? Exceptions being an open type allows you to classify failures. from Unix.ml: let rec waitpid_non_intr pid = try waitpid [] pid with Unix_error (EINTR, _, _) -> waitpid_non_intr pid With a closed type, there is not much you can do to ensure that you catch the right type of exception here (matching on strings? seems much worse). Note that, as there is no break keyword in the language, you tend to use exceptions for control flow to avoid rewriting your for loops to while loops. You can write some APIs without exposing exceptions, the same way that you can write an API without exposing a global hash-table. Exceptions are just a tool, that allow you to work around some limitations / performance issues / make your life easier. Removing them is impossible at this point for compatibility reasons, so all you can do is avoid using them if it makes you sad (the same way you avoid using some parts of the language when you program in c++ / ecmascript / whatever language du jour). Nathan On 20 October 2017 at 11:56, Malcolm Matalka wrote: > I have a question in two parts: > > 1. Would this be a good idea? Why? (I'll describe why I think it is) > > 2. If it were a good idea, is it feasible to do? > > Full question: > > Despite exceptions being a part of the language, there is a trend in > many libraries to try to avoid using them. While I cannot find it, I > recall someone (Daniel maybe?) saying that the standard API advice is > that exceptions should not cross API boundaries. > > The short reason for why people seem to want to avoid exceptions (which > I agree with) is that they side step the type system for helping you > understand if your code is correct and handles all situations the code > might experience. Since the exn type is open, it means that one can add > any exception they want so it's not even known what exceptions you might > get ahead of time. > > Another aspect of exceptions, which might be more of my personal > experience, is that exceptions tend to be pretty useless after the > fact. For example, forgetting to handle a Not_found exception is an > exercise in pain. Maybe I'm just bad at this, but many exceptions just > aren't that useful. End_of_file is another one that, IMO, makes the > program flow pretty awkward and if you have multiple files you're > reading from at the same time quite ugly. I tend to use wrappers that > give me an option based API. Maybe I just bad at solving these problems > though and I'm the problem. > > The consequence of this is that even though I put a lot of effort in my > code trying to avoid exceptions, I can never actually know that I have > succeeded unless I'm very defensive and wrap all foreign calls in some > exception handling code. There are APIs for this, but if I mess up then > I'm in a bad spot. > > My proposal is that exceptions becomes a closed type and they reflect > what Java calls "errors", which are things your program logic should > generally not handle but can choose to if it wants to (I think we call > these failures in Ocaml). The two specific exceptions I can think if > that should exist are: Assertion_failure and Out of Memory. Another one > that I think might be nice but is open for debate is a > Not_implemented_failure, I use something like this often while building > a system. I'm sure there are a few more that people can think of are > meaningful, but the point is these represent pretty bad situations that > the program logic shouldn't handle except in special situations. > > Thanks for reading, > /Malcolm > > -- > 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