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 aliases and recursive modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-05-15 (16:57)
From: Josh Berdine <berdine@d...>
Subject: RE: [Caml-list] type aliases and recursive modules


Josh Berdine wrote:


> Hi,


> There's something I'm not understanding about recursive modules. 

> Consider the following distilled example:



      [snip buggy simplification]



> Why doesn't the typechecker know that ASet.t and C.t are the same 

> type? Anyone know a workaround?


> This is with the 3.10.0 beta version, but seems to be the same back to 

> 3.07.


> Cheers, Josh





There is an incoherency in your definition of ASet.get_its_elements.


In the signature of ASet, get_its_elements take an argument of type 

ASet.t, but then in its definition, it takes an argument of type A.t (as 

A.get takes an argument of type A.t, and you give ASet.get_its_elements' 

argument to A.get)



Philippe Wang




Thanks Philippe and Christopher, yes, mea culpa, I forgot, e.g., a call to
choose.  But my confusion remains:




module rec A : sig

  type t = It of ASet.t

  val compare : t -> t -> int

  val get : t -> ASet.t

end = struct

  type t = It of ASet.t

  let compare = compare

  let get = function It(x) -> x



and ASet : sig

  type t

  val get_its_elements : t -> A.t list

end = struct

  module C = Set.Make(A)

  type t = C.t

  let get_its_elements x = C.elements (A.get (C.choose x))



                                      Characters 350-370:

    let get_its_elements x = C.elements (A.get (C.choose x))


This expression has type ASet.t but is here used with type

  C.t = Set.Make(A).t




Am I still doing something stupid?


Cheers,  Josh