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 8DA197EE5B for ; Mon, 26 May 2014 18:34:41 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of daniel.buenzli@erratique.ch) identity=pra; client-ip=74.55.86.74; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="daniel.buenzli@erratique.ch"; x-sender="daniel.buenzli@erratique.ch"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of daniel.buenzli@erratique.ch) identity=mailfrom; client-ip=74.55.86.74; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="daniel.buenzli@erratique.ch"; x-sender="daniel.buenzli@erratique.ch"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp.webfaction.com) identity=helo; client-ip=74.55.86.74; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="daniel.buenzli@erratique.ch"; x-sender="postmaster@smtp.webfaction.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArQBACtsg1NKN1ZKlWdsb2JhbABZhxuqWJROAYErDgEBAQEHDQkJEiqCJgEFIwRSEAsaAiYCAkcQBhuIOgSvPqVcF4EqiAmEbDMHgnU2gRUBA6BHF492 X-IPAS-Result: ArQBACtsg1NKN1ZKlWdsb2JhbABZhxuqWJROAYErDgEBAQEHDQkJEiqCJgEFIwRSEAsaAiYCAkcQBhuIOgSvPqVcF4EqiAmEbDMHgnU2gRUBA6BHF492 X-IronPort-AV: E=Sophos;i="4.98,914,1392159600"; d="scan'208";a="76466021" Received: from mail6.webfaction.com (HELO smtp.webfaction.com) ([74.55.86.74]) by mail2-smtp-roc.national.inria.fr with ESMTP; 26 May 2014 18:34:40 +0200 Received: from [172.20.10.2] (112-236.197-178.cust.bluewin.ch [178.197.236.112]) by smtp.webfaction.com (Postfix) with ESMTP id 34D4322884CE; Mon, 26 May 2014 16:34:36 +0000 (UTC) Date: Mon, 26 May 2014 18:34:33 +0200 From: =?utf-8?Q?Daniel_B=C3=BCnzli?= To: Philippe Veber Cc: Ben Millwood , Romain Bardou , caml users Message-ID: <53B801AD6F5B4BFBA0DA2A69D8775497@erratique.ch> In-Reply-To: References: <53835610.9050609@inria.fr> X-Mailer: sparrow 1.6.4 (build 1178) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Subject: Re: [Caml-list] Uncaught exceptions in function type. Le lundi, 26 mai 2014 =C3=A0 18:02, Philippe Veber a =C3=A9crit : > Thanks! BTW core still uses exceptions. Is there an explicit rule as to h= ow to decide between Result type or exceptions. For instance, why not write= the Array.create function like this: >=20=20 > val create : int -> 'a -> 'a array Or_error.t >=20=20 > where create fails for a negative integer? Because that would be utterly annoying. You need to make the following dist= inctions: * Programming errors, for contracts with the programmer that cannot be enfo= rced through types. For that raises Invalid_argument if the contract is vio= lated. Invalid_argument is not supposed to be handled, it denotes an API mi= suse, like calling Array.create with a negative integer. * Exceptional errors, for errors that the programmer is unlikely to handle = at all (e.g. out of memory). For that raise a custom exception. This should= occur very rarely, you are unlikely to ever define one such exception. * Non-exceptional errors, errors that the programmer will have to handle (e= .g. failing to connect a socket), for that do not use a custom exception bu= t use variants or options types.=20=20 In general if you write libraries it=E2=80=99s better to err on the side of= exceptionless design: never use exceptions beyond Invalid_argument (and es= pecially never use Not_found or Failure). Leave exception definition/usage = at the discretion of the user (if he wishes to shoot himself in the foot). Best, Daniel