From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q357rMcs008648 for ; Thu, 5 Apr 2012 09:53:23 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkACAPROfU/RVdK2mGdsb2JhbABDhXyhH5FFCCIBAQEBAQgJDQcUJ4IJAQEBBBICDwQZAQEsCwEPCQILAwoCAgkIFQICIQESAQUBChIGExIQh10BAwsLoSQKilpugz8BhH4KQAMKgWUGgS+IaYMHghiBGJVsgRGKJYMdPYQL X-IronPort-AV: E=Sophos;i="4.75,374,1330902000"; d="scan'208";a="152794519" Received: from mail-iy0-f182.google.com ([209.85.210.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 05 Apr 2012 09:53:22 +0200 Received: by mail-iy0-f182.google.com with SMTP id k25so2378541iah.27 for ; Thu, 05 Apr 2012 00:53:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=YpTWTnPLPLm6DeCqrYDF0EBWJUXNC94nS2BpBY7TlPw=; b=HIE6q8IoQc7p7zGG91i4bSMCwe3j1v3CfFEtl0TkZcsnGLgm1RcLcACGfbyxQSK6cl vnnrAjXVHerqd0fgiVhXcmYeFCGaEZpaxZTmU2+/qQnVbkQcWq4sbs9Ne+dJRU2BTQ93 Unhgf3LNxxsYS6xh7kMXW3090AN/2MyqIhi9PbzlZ9THdiFIZz8Ej2KMsRBkH7NcDj3d F5uwFA3j+QJi4RiEbyxYEj4odsN6TriVg/uukI07UvNxSxIVB7t6BuhOj9NI73wkthFz raXiNXZnuxJY3lcVZX4mhT2R5K/xrZzLH13VCTq0gdkRBNLLsi6txNMqerT+fGUHzaUn LTFg== MIME-Version: 1.0 Received: by 10.50.45.167 with SMTP id o7mr1207787igm.22.1333612402732; Thu, 05 Apr 2012 00:53:22 -0700 (PDT) Received: by 10.231.205.204 with HTTP; Thu, 5 Apr 2012 00:53:22 -0700 (PDT) In-Reply-To: References: Date: Thu, 5 Apr 2012 08:53:22 +0100 Message-ID: From: Benedikt Grundmann To: Raphael Proust Cc: Pierre Chopin , caml-list@inria.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id q357rMcs008648 X-Validation-by: benedikt.grundmann@googlemail.com Subject: Re: [Caml-list] exn vs option That post is against maybe (aka option) as an error type as it looses information about the error. If you use an Either type such as Core's Result.t that argument is invalidated. In fact at Jane Street we try avoid the use of exceptions as they don't force the client of the library to handle the exceptional case. Also exceptions don't immediately imply more information one of the most wide spread exceptions in OCaml's stdlib is Not_found which can be a nightmare to hunt down (in particular if for whatever reason you did not also have a backtrace). Cheers, Bene On 5 April 2012 07:45, Raphael Proust wrote: > Aside from performance considerations, there are semantics differences > to take into account. This blog post explain why exceptions are > "better" (or, more precisely, why it is not generally a good idea to > replace exceptions by options) > http://blog.dbpatterson.com/post/9528836599 (it is in Haskell rather > than OCaml, but it still applies). > > On Wed, Apr 4, 2012 at 10:25 PM, Pierre Chopin wrote: >> Hi, >> >> I benchmarked two programs, in one case the main function throw an exception >> that is caught, in the other the function returns an option that is pattern >> matched on. >> >> I noticed that, whether the exception is thrown or not, the option version >> is always faster. >> >> Is there any case where it makes sense, performance wise, to use exception >> instead of 'a option ? >> >> test1.ml >> ---------------------------------------------------------------------- >> >> exception Foo >> let f x = >>  if x =1 then raise Foo else () >> >> ;; >> >>  for i = 0 to 10_000_000 do >> try >>     f 1 >> with Foo -> () >> done >> ------------------------------------------------------------------------ >> test2.ml: >> ------------------------------------------------------------------------ >> let f x = >>     if x=1 then None else Some () >> >> ;; >> for i = 0 to 10_000_000 do >>     match f 1 with >>         None -> () >>     |   Some s -> s >>     done >> ------------------------------------------------------------------------ >> >> >> >> -- >> Pierre Chopin, >> Chief Technology Officer and co-founder >> punchup LLC >> pierre@punchup.com >> > > > > -- > _______ > Raphael > > > -- > Caml-list mailing list.  Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > -- Calvin: I try to make everyone's day a little more surreal. (From Calvin & Hobbes)