From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p49ERAus031166 for ; Mon, 9 May 2011 16:27:10 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ai4BANr4x00machzl2dsb2JhbACYEI4AAQEBAQEIFgc5pzqee4YMBJQNilE X-IronPort-AV: E=Sophos;i="4.64,340,1301868000"; d="scan'208";a="107889712" Received: from mx2.janestreet.com (HELO nyc-dmz-mxout2.janestreet.com) ([38.105.200.115]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 09 May 2011 16:27:05 +0200 Received: from [172.25.22.57] (helo=nyc-qsv-mail1.delacy.com) by nyc-dmz-mxout2.janestreet.com with esmtp (Exim 4.71) (envelope-from ) id 1QJRQN-000558-4h for caml-list@inria.fr; Mon, 09 May 2011 10:27:03 -0400 Received: from nyc-qws-r25.delacy.com ([172.25.65.191] helo=janestreet.com) by nyc-qsv-mail1.delacy.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71) (envelope-from ) id 1QJRQN-0000r7-0r for caml-list@inria.fr; Mon, 09 May 2011 10:27:03 -0400 Date: Mon, 9 May 2011 10:27:02 -0400 From: Yaron Minsky To: caml-list@inria.fr Message-ID: <20110509142702.GZ28842@janestreet.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-JS-Compliance: sender=yminsky recipient=caml-list (ld) Subject: [Caml-list] "with module" surprises 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