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 <raphla...@gmail.com> 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 <pie...@punchup.com> 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
>> pie...@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)


-- 
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

Reply via email to