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
Modules within classes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-09-13 (07:44)
From: Martin Hofmann <mhofmann@t...>
Subject: Modules within classes
Dear all, 

Can someone explain what is wrong here and perhaps suggest a workaround? 

class ['a] test ( l : 'a list) = 
   method result = 
     let module M = 
        type t = 'a      
        let compare x y =
          if x < y then -1 else if x > y then 1 else 0
    let module MSet = Set.Make(M)
    in  MSet.elements (List.fold_right MSet.add l MSet.empty) 

OCaml says: "Unbound type parameter 'a". 

Our aim is of course not to program sorting the umpteenth time but to 
have a means for using Pervasives.Set within a parametrised class.

The problem seems to be that although "class ['a]" binds 'a its use is 
nevertheless disallowed in the scope of the class declaration. 

Many thanks in advance!

Martin Hofmann (on behalf of Oliver Friedmann)