Version française
Home     About     Download     Resources     Contact us    
Browse thread
Type from local module would escape its scope?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Bruno De Fraine <Bruno.De.Fraine@v...>
Subject: Re: [Caml-list] Type from local module would escape its scope?
On 03 Jul 2006, at 15:51, Virgile Prevosto wrote:
> IIRC arguments can not have a generalized type of the form
> "forall 'a, 'a -> unit", but methods and record fields support such
> types: for instance, you can have:

Thanks for your explanations! To get closer to the problem that  
caused me to investigate the error: so there is no way to make f1  
into an argument in the following function iter_uniques (other than  
as a method or record field)?

let f1 add empty = List.fold_right add ["foo"; "bar"; "bar"] empty ;;
let f2 = print_endline ;;

let iter_uniques comparison_fun =
   let module StringSet =
   Set.Make(struct
     type t = string
     let compare = comparison_fun
   end) in StringSet.iter f2 (f1 StringSet.add StringSet.empty)
;;

Because in case I didn't require a dynamic comparison function, I  
would simply write:

module StringSet = Set.Make(String) ;;

let iter_uniques f1 f2 =
   StringSet.iter f2 (f1 StringSet.add StringSet.empty)
;;

Regards,
Bruno