Version française
Home     About     Download     Resources     Contact us    
Browse thread
A functor to produce recursive modules ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Fabrice Marchant <fabrice.marchant@o...>
Subject: Re: [Caml-list] A functor to produce recursive modules ?
  Thanks a lot Alain !

> > The problem is I need recursive functors that returns 2 modules.
> 
> I'm not sure to understand. Maybe a functor that returns a pair of 
> mutually recursive modules is what you want.
  That's it !

> module F(X : Set.OrderedType) = struct
>    module rec Mod : sig
>      type t = X of int * ModSet.t
>      val compare: t -> t -> int
>      val of_list: t list -> t
val of_list: int -> ModSet.elt list -> t
>    end
>      =
>    struct
>      type t = X of int * ModSet.t
>      let compare (X (i, _)) (X (j, _)) = compare i j
>      let of_list i l = X (i, List.fold_right ModSet.add l ModSet.empty)
>    end
>    and ModSet : Set.S with type elt = Mod.t = Set.Make(Mod)
> end

  This was the kind of example I needed.
Up to now, I don't have written many functors. My problem here was simply I didn't thought to nest the two recursive modules inside a functor.
  This becomes obvious now.

   Regards,

Fabrice