From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 0FFC5BC57 for ; Thu, 27 May 2010 11:11:17 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAI/T/Usmachw/2dsb2JhbACeGHHAKIUTBIkp X-IronPort-AV: E=Sophos;i="4.53,310,1272837600"; d="scan'208";a="60118671" Received: from mx1.janestreet.com ([38.105.200.112]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 27 May 2010 11:11:16 +0200 Received: from nyc-qsv-mail1.delacy.com ([172.25.22.57]) by mx1.janestreet.com with esmtp (Exim 4.71) (envelope-from ) id 1OHZ7S-0008La-7p for caml-list@yquem.inria.fr; Thu, 27 May 2010 05:11:14 -0400 Received: from nyc-qsv-004.delacy.com ([172.25.22.194] helo=qsmtp.delacy.com) by nyc-qsv-mail1.delacy.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.71) (envelope-from ) id 1OHZ7S-0008P9-Gb; Thu, 27 May 2010 05:11:14 -0400 Received: from ldn-qws-r01.delacy.com ([172.23.65.101] helo=ldn-qws-r01) by qsmtp.delacy.com with smtp (Exim 4.71) (envelope-from ) id 1OHZ7P-0008KZ-7T; Thu, 27 May 2010 05:11:14 -0400 Received: by ldn-qws-r01 (sSMTP sendmail emulation); Thu, 27 May 2010 10:11:10 +0100 From: "Mark Shinwell" Date: Thu, 27 May 2010 10:11:10 +0100 To: David Allsopp Cc: 'Florent Ouchet' , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Static exception analysis or alternative to using exceptions Message-ID: <20100527091110.GD18772@janestreet.com> References: <956439.81564.qm@web111506.mail.gq1.yahoo.com> <4BFE2881.1070705@imag.fr> <000c01cafd7a$3f6595e0$be30c1a0$@romulus.metastack.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <000c01cafd7a$3f6595e0$be30c1a0$@romulus.metastack.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Spam: no; 0.00; shinwell:01 0100,:01 hashtbl:01 popping:01 refactor:01 exn:01 exn:01 variants:01 hacks:01 wrote:01 wrote:01 exception:01 exception:01 assert:01 caml-list:01 On Thu, May 27, 2010 at 09:54:29AM +0100, David Allsopp wrote: > Florent Ouchet wrote: > > Same here, specially to avoid the Not_found exception. > > The optional return values gives the oportunity to have a clear view of > > what is being done if the result is not available. > > Agreed - though [find] is one of the examples where you do need find and > find_exc - because often there are occasions where before calling > {Map,Set,Hashtbl}.find you already know that the key exists and so won't > fail at which point the 'a option boxing is a waste of time and space and > Not_found would be a truly exceptional situation so passes the previously > mentioned test. I don't think I agree with this. I would argue that for the majority of programs it is likely that the extra overhead is in fact negligible. In the cases where it should be impossible to get the None return value, I think that should probably be annotated as such in the code with "assert false", which would seem to be more appropriate than a random Not_found popping up at some much higher level. In some cases it might be possible to refactor the code to just avoid the situation entirely, for example by turning this: if not (Map.mem my_map key) then ..a.. else ..b.. let data = Map.find_exn my_map key in ..c.. into this: match Map.find my_map key with | None -> ..a.. | Some data -> ..b.. ..c.. Whilst I agree that there are arguments relating to verbosity of the use of option types, I think the strongest argument for keeping the *_exn variants may actually be that they're just a lot more convenient for quick hacks. Mark