Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: Alain Frisch <alain@f...>
Subject: Re: [Caml-list] A functor to produce recursive modules ?
Fabrice Marchant wrote:
> Hi !
>    Apologize. This topic isnt't exactly at its right place : belongs to Beginners-list.
> However no answer about this question there and so much clever people here, a denser traffic...
>    Please how to define recursive modules that are parametrized by an OrderedType ?
> Say these modules types are Mod and ModSet.
> (Because a function f in module Mod uses a Set of Mod)
> 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.

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
     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)
   and ModSet : Set.S with type elt = Mod.t = Set.Make(Mod)

-- Alain