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
[Caml-list] Re: OCAML Downcasting?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-09-22 (10:00)
From: sejourne_kevin <sejourne_kevin@y...>
Subject: Re: [Caml-list] Re: OCAML Downcasting?
Marcin 'Qrczak' Kowalczyk wrote:
> skaller <> writes:
>>>Attempts to avoid downcasts are often unmodular, they require to
>>>specify all possible variants in one place.
>>It makes no difference. You have do specify them all anyhow,
>>downcast or not.
> It makes a difference because specifying them at the type definition
> would introduce a dependency loop between modules. And it would be
> unmodular: it would require changing some base module whenever a far
> client module is added.
> Apply this reasoning to the exn type. Why don't you define all exn
> constructors in one place?

I think there is no problems with exceptions. But if you have problems 
managing exceptions in large modules have you try something like this ?

here an example:
I define all my exceptions like this :

let errors = ref [];;

(*to define an error*)
(*errors     "the exception" , the new value*)
errors :=   ("div by zero"   ,0)              :: (!errors);;

And the functions catch errors in this way:
let truc () =
      ... all Ocaml pre-defined exceptions
     | exn -> (* my exceptions in  errors list ref *)
	let s = Printexc.to_string exn in
	  ... Lex & Parse 's' in (fst errors) ref list , then handle error ...

If exceptions are complex I can use polymorphic variants
for the "new value".

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: