English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2006-07-03 (14:51)
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 =
     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)