From: Lukasz Stafiniak <lukstafi@gmail.com>
To: Nicolas Pouillard <nicolas.pouillard@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Static exception analysis or alternative to using exceptions
Date: Mon, 31 May 2010 22:57:44 +0200 [thread overview]
Message-ID: <AANLkTil7kXzh-dJ6rEohK7OvQuVqz3bc6ToEdmZTbGa2@mail.gmail.com> (raw)
In-Reply-To: <4c040e62.9608e30a.4b34.6623@mx.google.com>
On Mon, May 31, 2010 at 9:30 PM, Nicolas Pouillard
<nicolas.pouillard@gmail.com> wrote:
>
> Since having all functions in all flavours can lead to hard to interface
> bloat, one should consider tiny functions to switch from a style to another.
> It tends to be easier to start from an option type in the case of Not_found
> instead of the other way around for the following reason:
>
> * The typechecker does not remind us to catch the exception.
> * We need a custom handler per exception.
> * We need to take a thunk to delay the computation.
>
> let not_found_to_option f =
> try Some (f ())
> with Not_found -> None
>
> On the contrary look at:
>
> let from_option exn = function
> | Some x -> x
> | None -> raise exn
>
> Example: from_option Not_found (List.find p xs)
>
I use a syntax extension that catches "Not_found" and raises a failure
instead, with the source location of the "real" offending call. I do
this mostly because OUnit catches exceptions so backtraces are of no
use. When I use the unmodified calls, I always handle Not_found right
away, close to call point -- either by directly catching it, or by
using a higher-order function, like an iterator that expects Not_found
instead of None from the callee. Anyway, I vote for "option"ising all
of the standard library and providing the function "unsome" raising a
string with source code location of its call.
next prev parent reply other threads:[~2010-05-31 20:57 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-26 16:15 Hans Ole Rafaelsen
2010-05-27 9:34 ` [Caml-list] " Alain Frisch
2010-05-27 17:01 ` Richard Jones
2010-05-27 21:13 ` Dario Teixeira
2010-05-31 14:36 ` Goswin von Brederlow
2010-05-31 15:00 ` Florent Ouchet
2010-05-31 17:24 ` David Allsopp
2010-05-31 20:51 ` Török Edwin
2010-06-08 9:16 ` Goswin von Brederlow
2010-05-31 19:30 ` Nicolas Pouillard
2010-05-31 20:57 ` Lukasz Stafiniak [this message]
2010-05-31 21:42 ` blue storm
2010-05-31 19:36 ` Christophe Raffalli
2010-05-26 17:30 Dario Teixeira
2010-05-26 21:10 ` Hans Ole Rafaelsen
2010-05-27 3:37 ` Jacques Le Normand
2010-05-27 8:08 ` Florent Ouchet
2010-05-27 8:50 ` Eray Ozkural
2010-05-27 11:10 ` Florent Ouchet
2010-05-27 8:54 ` David Allsopp
2010-05-27 9:11 ` Mark Shinwell
2010-05-27 9:29 ` David Allsopp
2010-05-27 9:12 ` Daniel Bünzli
2010-05-27 9:19 ` David Allsopp
2010-05-27 9:15 ` David Rajchenbach-Teller
2010-05-27 13:56 ` Hezekiah M. Carty
2010-06-01 19:08 Peter Ronnquist
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTil7kXzh-dJ6rEohK7OvQuVqz3bc6ToEdmZTbGa2@mail.gmail.com \
--to=lukstafi@gmail.com \
--cc=caml-list@inria.fr \
--cc=nicolas.pouillard@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox