caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michael Furr <furr@cs.umd.edu>
To: <caml-list@inria.fr>
Subject: Recursive module signatures + functors
Date: Mon, 11 Jun 2007 19:10:25 -0400 (EDT)	[thread overview]
Message-ID: <Pine.SOL.4.33.0706111848240.11389-100000@loompa.cs.umd.edu> (raw)


I've been playing around with using recursive modules to implement mixins
and don't understand why the type checker fails to accept code below.
Assume I have the following functor:

  module Mix(M : type t val f : t -> t) = struct
    let f_twice x = M.f (M.f x)
  end

If I then write:

  module type S = sig
    type t
    val f : t -> t
    val f_twice : t -> t
  end
  module rec M : S = struct
    type t = int
    let f t = t + 1
    include Mix(M)
  end

then the type checker complains
  Signature mismatch:
  Modules do not match:
    sig type t = int val f : int -> int val f_twice : M.t -> M.t end
  is not included in
    S
  Values do not match:
    val f_twice : M.t -> M.t
  is not included in
    val f_twice : t -> t

I don't quite understand why the type system doesn't know that t and M.t
are the same.  However, if I inline the signature and directly reference
M.t there, it works:

  module rec M : sig
    type t
    val f : t -> t
    val f_twice : M.t -> M.t  (* Note M. prefix *)
  end = struct
    type t = int
    let f t = t + 1
    include Mix(M)
  end

Is this a bug in the type checker or is there a reason that it does not
unify 't' and 'M.t'?


Cheers,
-Mike

P.S. This is with 3.10.0.




             reply	other threads:[~2007-06-11 23:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-11 23:10 Michael Furr [this message]
2007-06-12  8:51 ` [Caml-list] " rossberg
2007-06-12  9:47 ` Xavier Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.SOL.4.33.0706111848240.11389-100000@loompa.cs.umd.edu \
    --to=furr@cs.umd.edu \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).