From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id EF5BD82355 for ; Tue, 23 Jan 2018 15:48:50 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=oleg@okmij.org; spf=Pass smtp.mailfrom=oleg@okmij.org; spf=None smtp.helo=postmaster@mail1.g3.pair.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of oleg@okmij.org) identity=pra; client-ip=66.39.3.114; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="oleg@okmij.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of oleg@okmij.org designates 66.39.3.114 as permitted sender) identity=mailfrom; client-ip=66.39.3.114; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="oleg@okmij.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail1.g3.pair.com) identity=helo; client-ip=66.39.3.114; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="oleg@okmij.org"; x-sender="postmaster@mail1.g3.pair.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3A6BE2UBOGUL0TLsqHesQl6mtUPXoX/o7sNwtQ0KIM?= =?us-ascii?q?zox0LPn5rarrMEGX3/hxlliBBdydt6odzbKO+4nbGkU4qa6bt34DdJEeHzQksu?= =?us-ascii?q?4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1?= =?us-ascii?q?Ov71GonPhMiryuy+4ZLebxlViDanfb9+MAi9oBnMuMURnYZsMLs6xAHTontPde?= =?us-ascii?q?RWxGdoKkyWkh3h+Mq+/4Nt/jpJtf45+MFOTav1f6IjTbxFFzsmKHw65NfqtRbY?= =?us-ascii?q?UwSC4GYXX3gMnRpJBwjF6wz6Xov0vyDnuOdxxDWWMMvrRr0yRD+s7bpkSAXwhS?= =?us-ascii?q?kJNzA37nzZhM9/g61HvR2uqQdyw5LIbIyPKPZyYrnQcc0cSGFcXshRTStBAoak?= =?us-ascii?q?YoUWC+oOI+lYpJT6qlsJqRuxGwasCfjoyj9Lg3/23K863/4mEQHc0wwtBtQDu2?= =?us-ascii?q?nXotXtLKofUOG4wLPGwDjHdf9b1y3x5JXVfh0uuf2AQ698fdbLxUUyGA7IjU+c?= =?us-ascii?q?pZH7Mz6VzOgAsGmW4ux9Xuy1kWEnsRt+oj23y8cslIbJgoUVx0jB9SpjwYY1Ic?= =?us-ascii?q?C0RFR0YdOqCpdQrzuVN4psQs84X25ovyM6xqUHuZ69YicK1Iwqyh/eZvCdfYWF?= =?us-ascii?q?5gjvWeiLLTtlmX5od6qzhxOo/kihzu38WNO00FFPriddldnMsm4C1xPI58iASf?= =?us-ascii?q?t9+0ah2TSV2wDU8OFELlg4lbDHJJ453r4wip0TvFzfESDsnUX2iLaadkEl+uiz?= =?us-ascii?q?9+Tqea7mp5+ZN49skA7yKKUumsqlAeQ5KAcCRWab+f7vnIHkqEbwRbEPivwtjo?= =?us-ascii?q?HYtorbLIIVvP2XGQhQh6En5hn3WzCi3dswmnoCLVADfwiI2du6c2rSKez1WK/s?= =?us-ascii?q?y2+nly1mkqifb+/RR67VJ32Gq4/POLN06kpS0g02lIkN4JFRC7NHJ+j8CBao6I?= =?us-ascii?q?7oSyQhOgnx+N7JTc1n39pHC2WMB66bdqTIvg3Qv799E6y3fIYQ/Q3FBb0l6vrp?= =?us-ascii?q?1C5rnFYcefDv0sBRcHm5BLJtJEDLOXc=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BhAgB0Smdah3IDJ0JeHgEGDIUcjxyNc?= =?us-ascii?q?ZtXCoozGQcENBQBAQEBAQEBAQEBARIBAQEKCwkIKC+COCKCdxN7NAWLEAGzeDq?= =?us-ascii?q?KZYRKghWBVosFgnyCNAWSNIEUkDaCBIEtkh8NhBmQCpdQgTw2gXJNMAiCaIIDU?= =?us-ascii?q?BAMgXaLXAEBAQ?= X-IPAS-Result: =?us-ascii?q?A0BhAgB0Smdah3IDJ0JeHgEGDIUcjxyNcZtXCoozGQcENBQ?= =?us-ascii?q?BAQEBAQEBAQEBARIBAQEKCwkIKC+COCKCdxN7NAWLEAGzeDqKZYRKghWBVosFg?= =?us-ascii?q?nyCNAWSNIEUkDaCBIEtkh8NhBmQCpdQgTw2gXJNMAiCaIIDUBAMgXaLXAEBAQ?= X-IronPort-AV: E=Sophos;i="5.46,401,1511823600"; d="scan'208";a="252200431" Received: from mail1.g3.pair.com ([66.39.3.114]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Jan 2018 15:48:49 +0100 Received: from mail1.g3.pair.com (localhost [127.0.0.1]) by mail1.g3.pair.com (Postfix) with ESMTP id 21AF73FB911; Tue, 23 Jan 2018 09:48:47 -0500 (EST) Received: from Magus.localnet (86.125.148.210.rev.vmobile.jp [210.148.125.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail1.g3.pair.com (Postfix) with ESMTPSA id 3BDA5582D0D; Tue, 23 Jan 2018 09:48:46 -0500 (EST) Date: Tue, 23 Jan 2018 23:54:53 +0900 From: Oleg To: caml-list@inria.fr Message-ID: <20180123145453.GA1916@Magus.localnet> Mail-Followup-To: Oleg , caml-list@inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.6.1 (2016-04-27) Subject: [Caml-list] Are record types generative? I have recently received a rather odd type error: Type declarations do not match: type t = D.Product.t = { pid : int; name : string; price : int; } is not included in type t = RProduct.t = { pid : int; name : string; price : int; } Apparently, two structurally identical record types are not regarded equal (OCaml 4.04.0). The original code is a bit complicated, so let me illustrate the problem on a simple example: module type m1 = sig type t = int val v : t end module M1 : m1 = struct type t = int let v = 1 end module F1(S:m1) = struct let res = S.v = M1.v end let _ = let module M = F1(M1) in M.res;; This code is accepted with no problems and gives the expected result (1 is indeed equal to 1). Module M1 was checked to satisfy the signature m1; therefore, S.v and M1.v should have the type int and be the same. Let's change the example slightly module type m2 = sig type t = {l:int} val v : t end module M2 : m2 = struct type t = {l:int} let v = {l=1} end module F2(S:m2) = struct let res = S.v = M2.v end Characters 43-47: let res = S.v = M2.v ^^^^ Error: This expression has type M2.t but an expression was expected of type S.t Although both M2 and S are two instances of m2, and hence both S.v and M2.v should have the record type t = {l:int}, they are not regarded equal. The problem is easy to fix: module F3(S:m2 with type t = M2.t) = struct let res = S.v = M2.v end ;; module F3 : functor (S : sig type t = M2.t = { l : int; } val v : t end) -> sig val res : bool end let _ = let module M = F3(M2) in M.res;; but even in this simple case the fix is ugly (and becomes uglier in the real code). Maybe there is a way to avoid adding too many sharing constraints? BTW, the new manual has a section about common polymorphism pitfalls. Modules also have a fair share of dark corners (along with the objects). Perhaps there could be a section in the manual about not so obvious aspects of modules (in the first approximation, just collecting questions and answers like the present one).