Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] Bugs with pattern-matching and exceptions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-03-02 (06:47)
From: Alain Frisch <Alain.Frisch@i...>
Subject: Re: [Caml-list] Bugs with pattern-matching and exceptions
Louis Gesbert wrote:
> Let's suppose we have two processes running the exact same compiled program.

I guess exceptions are too dynamic for this criterion to be useful.
You could imagine an implementation of exception equality based on 
unique integers assigned sequentially to exception constructors when 
they are created. But this doesn't work in general. Consider:

let f b =
   let module M = struct exception E end in
   if b then Marshal.to_channel stdout M.E []
   else match Marshal.from_channel stdin with
      | M.E -> print_endline "Equal"
      | _ -> print_endline "Not equal"

let () =
   if (Array.length Sys.argv >= 2) then f true else f false

I don't see a good semantics for such a program, except considering that 
unmarshalled exceptions must always be different (w.r.t. pattern 
matching) from exceptions defined in the current program, which AFAIK is 
the current semantics.

> However, if you try to pattern-match against it, the process just hangs.

Can you give an example to reproduce that?  The program above works fine.

leoville ~/bug $ ./exn x | ./exn
Not equal

> As I understand it, the constructor Ex of the variant type exn is
> represented by a pointer in (Ex "arg"), and this pointer is kept as-is by
> the marshaller which doesn't understand the particular structure of
> exceptions.

More precisely, it doesn't distinguish an exception constructor from a 
string reference. Marshalling and unmarshalling produce a shallow copy.

-- Alain