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
Problem with Functors and Module Types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-08-01 (11:11)
From: Christian Sternagel <christian.sternagel@u...>
Subject: Problem with Functors and Module Types

once again I have some problems using functors with module types. I 
produced following (almost?) minimal example:

     module type MT_M = sig
      type s
      type t = A of s | B of t list
      val f : t -> t

     module type MT_N = sig
      module M : MT_M
      val f : 'a -> M.t

     module type MT_A = sig
      type t

     module MakeM (A : MT_A) : MT_M with type s = A.t = struct
      type s = A.t
      type t = A of s | B of t list
      let f x = x

     module MakeN (A : MT_A) (* : MT_N *) = struct
      module M = MakeM (A)
      let f _ = M.B []

     module A = struct
      type t = int

     module M = MakeM (A)
     module N = MakeN (A)

     let _ = (M.f (N.f 1))

This file compiles, but when I comment-in the module type restriction 
for `MakeN' the error

This expression has type N.M.t = MakeN(A).M.t but is here used with type
   M.t = MakeM(A).t

occurs. I understand that in the current setting the two types are not 
equal for the compiler. However, my question is: Is there a way to tell 
the compiler that the two types should be equal?