Browse thread
[OSR] Exceptionless error management
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Bünzli_Daniel <daniel.buenzli@e...> |
| Subject: | Re: [Caml-list] [OSR] Exceptionless error management |
Le 31 janv. 08 à 15:09, Andrej Bauer a écrit :
> I have become to prefer option types as return values (as opposed to
> exceptions), but I admit it can be annoying to always consider both
> possibilities, especially if you know that "None" won't happen.
Maybe it is a point of view, you are fed up of considering both
possibilites while I'm personally fed up of writing
match try Some (f x) with e -> None with
| None -> ..
| Some v -> ...
Because I need tail recursive functions.
> If the library only provides "find" that returns an option type, the
> above solution gets around constant checking. But how much runtime
> overhead does it cause? Has anyone measured that?
No idea. Unscientific benchmark at the end of the email.
> What is wrong with having two functions?
You have to choose. You don't have exceptionless error mangement
anymore which is the point of the proposal. As the module developer I
don't want to write two functions to do the same thing albeit in a
slight different way one of which strikes me as the being the wrong way.
Best,
Daniel
osx 10.5.1 1ghz G4 512 ram
> cat in.ml
let () =
let f = ref [] in
try while (true) do f := (input_line stdin) :: !f done
with End_of_file -> ignore (!f)
> cat inb.ml
let () =
let rec next acc =
match try Some (input_line stdin) with End_of_file -> None with
| None -> acc
| Some l -> next (l :: acc)
in
ignore (next [])
> ocamlbuild in.native inb.native
Finished, 8 targets (0 cached) in 00:00:01.
> time jot 1000000 | ./in.native
real 0m4.814s
user 0m4.371s
sys 0m0.218s
> time jot 1000000 | ./inb.native
real 0m4.790s
user 0m4.355s
sys 0m0.217s