Version française
Home     About     Download     Resources     Contact us    
Browse thread
Resumable exceptions in plain OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: oleg@p...
Subject: Re: [Caml-list] Resumable exceptions in plain OCaml

Christophe Raffalli observed that

> rraise (Foo i) (function Foo_r1 x -> ... | e -> raise e)

"seems shorter, equivalent and more efficient" than 

>   rraise (Foo i) (fun e -> try raise e with Foo_r1 x -> ...) 

that appeared in the posted code.

I agree. In fact, to the best of my knowledge of the OCaml interpreter,
the former is the semantics of the latter -- or, to be even more
precise, the latter reduces to the former in the interpreter. The
reason I chose the latter is: (i) to avoid writing the default clause
"| e -> raise e", but mainly, (ii) to emphasize the similarity between
pattern matching on the value (when invoking a function, for example) and
pattern matching on the exception in the 'try' clause. The duality
seemed irresistible to pass.

> In fact exceptions in OCaml are one big polymorphic variant type that 
> existed before polymorphic variant where introduced ;-)

So true. One of the motivations for the code was to
(ab)use this fact.

Christophe Raffalli also suggested

>    rraise Foo i with Foo_r1 x -> ...
> is much clearer and certainly possible to define in camlp4 ?

I agree again. I specifically wanted to avoid camlp4 in the original
post, for the sake of naked details. Defining the right syntax, and
implementing it with camlp4, was to be the next step.