Hi, > > > exception Done of 'a > > > > let fold_file (file: in_channel) > > (read_func: in_channel->'a) > > (elem_func: 'a->'b->'b) > > (seed: 'b) = > > let rec loop prev_val = > > let input = > > try read_func file > > with End_of_file -> raise (Done prev_val) > > in > > let combined_val = elem_func input prev_val in > > loop combined_val > > in > > try loop seed with Done x -> x > In fact, if elem_func is known by the type checker not to raise any exception, then the exception need not to be garded by the Done constructor and the following program is safe: > let fold_file (file: in_channel) > (read_func: in_channel->'a) > (elem_func: 'a->'b->'b) > (seed: 'b) = > let rec loop prev_val = > let input = > try read_func file > with End_of_file -> raise prev_val > in > let combined_val = elem_func input prev_val in > loop combined_val > in > try loop seed with x -> x The only problem is that current type-checker do not treat exception well and reject this kind of code .... Just for fun (I could not resist), here is the pml code which is accepeted, but is useless since pml can not read file yet ;-) ---------- pml code --------- (* f,a,b are declared type variables, a => b is the type of a function that raises no exception a -> b | e is the type of a function that raises only exception of type e a -> b is the type of a function with no indication about exceptions *) val (f,a,b) fold_file:(f => (f -> a | [EOF[]]) => (a=>b=>b) => b => b) file read_func elem_func seed = let rec loop prev_val = let input = try read_func file with EOF[] -> raise prev_val in let combined_val = elem_func input prev_val in loop combined_val in try loop seed with x -> x ------------------------------- So the story is by saying (wrongly) that it is too heavy to anottate arrow types with exceptions, making the arrow type a ternary type construct, ML is missing a lot ... -- Christophe Raffalli Universite de Savoie Batiment Le Chablais, bureau 21 73376 Le Bourget-du-Lac Cedex tel: (33) 4 79 75 81 03 fax: (33) 4 79 75 87 42 mail: Christophe.Raffalli@univ-savoie.fr www: http://www.lama.univ-savoie.fr/~RAFFALLI --------------------------------------------- IMPORTANT: this mail is signed using PGP/MIME At least Enigmail/Mozilla, mutt or evolution can check this signature. The public key is stored on www.keyserver.net ---------------------------------------------