caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] "with module" surprises
@ 2011-05-09 14:27 Yaron Minsky
  2011-05-09 15:12 ` Markus Mottl
  0 siblings, 1 reply; 6+ messages in thread
From: Yaron Minsky @ 2011-05-09 14:27 UTC (permalink / raw)
  To: caml-list

I've gotten bitten recently by the semantics of "with module", and after
getting an explanation about how this seems to work in OCaml, I'm now
deeply confused.  Here's the example I was shown:

  module M = struct
    let x = 13
  end

  module type S = sig
    module M' : sig end
  end
  with module M' = M

The inferred types for this will be:

  module M : sig val x : int end
  module type S = sig module M' : sig val x : int end end

Whereas I would have expected this:

  module M : sig val x : int end
  module type S = sig module M' : sig end end

In other words, the "with module" constraint has added new structure to
the signature S, rather than just adding constraints.  This strikes me
as deeply strange, and indeed, has caused a bunch of head-scratching
here when using "with module".  Is this a bug?  Or is this really the
desired semantics.  My understanding is that in SML, "with module"
simply adds in a bunch of type-level sharing constraints.  From that
point of view, this behavior is pretty surprising.

Not only that, it's what the OCaml manual says.  From section 6.10.4

  The constraint [module module-path = extended-module-path] adds type
  equations to all type components of the sub-structure denoted by
  [module-path], making them equivalent to the corresponding type
  components of the structure denoted by [extended-module-path].
      
y

-- 
Yaron Minsky

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-05-09 18:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-09 14:27 [Caml-list] "with module" surprises Yaron Minsky
2011-05-09 15:12 ` Markus Mottl
2011-05-09 16:26   ` Yaron Minsky
2011-05-09 17:21     ` Markus Mottl
2011-05-09 17:33       ` Andreas Rossberg
2011-05-09 18:56         ` Markus Mottl

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).