From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p49FCflN000951 for ; Mon, 9 May 2011 17:12:41 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al4BAGYDyE3RVaG2kGdsb2JhbACXYI4VCBQBAQEBBwsNBxQEIao6jBmCMYRhNohfAQEDBoYGBI9liECCMTuDTQ X-IronPort-AV: E=Sophos;i="4.64,341,1301868000"; d="scan'208";a="82682525" Received: from mail-gx0-f182.google.com ([209.85.161.182]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 09 May 2011 17:12:35 +0200 Received: by gxk28 with SMTP id 28so2989716gxk.27 for ; Mon, 09 May 2011 08:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Xwz9mDi0jW0o8QWkvIu/qOGreXdr3+ddmzntIr+BwAQ=; b=SYT0Q8Ajpq3Z1XvSP2Obd698y1vO+y5oNpDsPDAAsV8u04V6b1A5WlRvuWKwj7RiKz dSN+C6H7hfovX15rk4Tr/CCHuPiXTXpsAUxewhL7UiVuX+aPGHnY/kOk7HkIr4P1THBy kbTEAmrreVovbu/dVyiEZpEXttq4Y12YroOlg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=ce6heJwlgjpQruFa7Z/Q6RTooqD906Jp+WN89T9VsheCVybTNLUuCEJoWvKuOyA6xz /wwjwwAppLFqKfQQgH3rQhL+jNZB6Odv4ip8BMNrU9TAbv1TYpHU0z5VNJRmmA4mfjZ/ iYL1Beis4gHVgvkPW+2UIq8LRSeyI5+vBL8M4= MIME-Version: 1.0 Received: by 10.150.63.8 with SMTP id l8mr5698197yba.290.1304953954439; Mon, 09 May 2011 08:12:34 -0700 (PDT) Received: by 10.147.178.15 with HTTP; Mon, 9 May 2011 08:12:34 -0700 (PDT) In-Reply-To: <20110509142702.GZ28842@janestreet.com> References: <20110509142702.GZ28842@janestreet.com> Date: Mon, 9 May 2011 11:12:34 -0400 Message-ID: From: Markus Mottl To: Yaron Minsky Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p49FCflN000951 Subject: Re: [Caml-list] "with module" surprises The current semantics seems to make sense to me. E.g. module type M' = sig type t end specifies that M' needs a type t. It doesn't say that a module matching this signature needs to keep t abstract. You can hence specialize this signature using "with" to e.g. require that it be an "int". Module constraints work similarly. If a signature is empty, this doesn't mean that a module matching it must not contain anything, rather the opposite: any module can match it. You can again specialize the signature using "with" to require further entries. The module passed to "with" only needs to match the first signature, which is trivially true in this case. Its own (possibly inferred) signature will then specialize the previous signature, potentially adding more entries. A maybe more intuitive way to think about this is following: in OCaml you can only make things more strict, never less strict. An empty signature is less strict (can be matched by more modules) than a non-empty one. Hence extending it is the right "direction". Markus On Mon, May 9, 2011 at 10:27, Yaron Minsky wrote: > 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 > > -- > Caml-list mailing list.  Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > -- Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com