From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id D4B1ABC57 for ; Tue, 7 Sep 2010 12:48:27 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoABAD61hUxKfVO2kGdsb2JhbACTFo1TCBUBAQEBCQkMBxEDH6Jji0iGMogJAQEDBYU4BIRBhVeIZw X-IronPort-AV: E=Sophos;i="4.56,328,1280700000"; d="scan'208";a="56785958" Received: from mail-pv0-f182.google.com ([74.125.83.182]) by mail3-smtp-sop.national.inria.fr with ESMTP; 07 Sep 2010 12:48:26 +0200 Received: by pvg4 with SMTP id 4so1960540pvg.27 for ; Tue, 07 Sep 2010 03:48:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:subject:mime-version :content-type:from:in-reply-to:date:cc:reply-to :content-transfer-encoding:message-id:references:to:x-mailer; bh=v8FurgA1xaVtqaU306pUk89CPCrX9TbP8sE1Bt/WFkA=; b=ddYL/nYm8YGSSNrQ9ZDaguAtPHwkDwO+7sxJNt86XLX80F0P4epKuxmN2Y8DHa0e/c rYXu5kRHm7BLZHwMWh8IfFy/AI3pGwQU2dgIPVgjM7/nbPXZYaneaRv+NjNErwk6Zyr1 cW3lRBQTtH8T+6rV0MrYUZHFv9UXpI2huBTj8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:subject:mime-version:content-type:from:in-reply-to:date:cc :reply-to:content-transfer-encoding:message-id:references:to :x-mailer; b=HjMjJQHGoY3PjyyVQQkuspnoeuiU9NL903ADOknw8aQoxRbDcWnRuGssFZPHlR3TZb unzX5leXkz58QwmCFJt4kZFbKMhUs/TPRSjS3SVOyl/tJyd0YLdbeJdkdgEsaX9EyVrt 0K2xcMtywO90AVJJZnQcZtiLl8SWxabaU5X0w= Received: by 10.114.95.12 with SMTP id s12mr2864709wab.217.1283856505779; Tue, 07 Sep 2010 03:48:25 -0700 (PDT) Received: from tet.garrigue.jp (58x158x128x157.ap58.ftth.ucom.ne.jp [58.158.128.157]) by mx.google.com with ESMTPS id r37sm13259893wak.11.2010.09.07.03.48.23 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 07 Sep 2010 03:48:25 -0700 (PDT) Sender: Jacques Garrigue Subject: Re: [Caml-list] functor substitution gives error Mime-Version: 1.0 (Apple Message framework v1081) Content-Type: text/plain; charset=us-ascii From: Jacques Garrigue In-Reply-To: <19588.45205.199003.965321@blau.inf.tu-dresden.de> Date: Tue, 7 Sep 2010 19:48:21 +0900 Cc: caml-list@inria.fr Reply-To: garrigue@math.nagoya-u.ac.jp Content-Transfer-Encoding: quoted-printable Message-Id: <29A499AD-55AD-4A5A-84EE-7BE4D0A98B14@gmail.com> References: <19588.45205.199003.965321@blau.inf.tu-dresden.de> To: Hendrik Tews X-Mailer: Apple Mail (2.1081) X-Spam: no; 0.00; functor:01 hendrik:01 tews:01 compilation:01 compiler:01 bug:01 functor:01 sig:01 camlp:01 syntax:01 camlp:01 syntax:01 struct:01 sig:01 ocaml:01 On 2010/09/06, at 18:12, Hendrik Tews wrote: > Hi, >=20 > I have a strange compilation problem, which I suspect to be a > compiler bug. Consider the following nested functor application >=20 >=20 > module A(FreshGram : functor(Unit : sig end) -> Camlp4Syntax) : = Camlp4Syntax =3D > FreshGram(struct end) >=20 > module B(FreshGram : functor(Unit : sig end) -> Camlp4Syntax) : = Camlp4Syntax =3D > Printers_Ocaml_Make(A(FreshGram)) >=20 >=20 > This compiles fine, however, when I manually inline functor A: >=20 >=20 > module C(FreshGram : functor(Unit : sig end) -> Camlp4Syntax) : = Camlp4Syntax =3D > Printers_Ocaml_Make(FreshGram(struct end)) >=20 >=20 > I get a signature mismatch error in both 3.11.2 and 3.12. I would > appreciate any explanation for this behaviour. The reason is that the typing of modules is not closed under = substitution. More precisely, the use of anonymous modules (the "struct end" in your code) is highly disruptive. It requires all modules around it to have non-dependent signatures, whereas the ability to express dependency is the great strength of applicative functors... Actually, all the theory was built assuming that there no anonymous = modules. The solution is easy enough: name all modules. Here you just have to write: module Unit =3D struct end module C(FreshGram : functor(Unit : sig end) -> Camlp4Syntax) : = Camlp4Syntax =3D Printers_Ocaml_Make(FreshGram(Unit)) Hope this helps. Jacques Garrigue > As the names suggest the problem came up with in some Camlp4 > code. Here is a striped down version, which reproduces the > problem: >=20 > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > module type Loc =3D sig (* simplified version of = Camlp4.Sig.Loc *) > type t > end >=20 > module type Camlp4Ast =3D sig (* simplified = Camlp4.Sig.Camlp4Ast *) > module Loc : Loc > end >=20 > module type Camlp4Syntax =3D sig (* simplified = Camlp4.Sig.Camlp4Syntax *) > module Loc : Loc > module Ast : Camlp4Ast with module Loc =3D Loc > end >=20 > module type Printers_Ocaml_Make_Sig =3D (* .mli of = Camlp4/Printers/OCaml *) > functor(Syntax : Camlp4Syntax) ->=20 > sig > include Camlp4Syntax > with module Loc =3D Syntax.Loc > and module Ast =3D Syntax.Ast > end >=20 > module Printers_Ocaml_Make : (* .ml of = Camlp4/Printers/OCaml *) > Printers_Ocaml_Make_Sig =3D functor(Syntax : Camlp4Syntax) -> > struct > include Syntax > end >=20 >=20 > module A(FreshGram : functor(Unit : sig end) -> Camlp4Syntax) : = Camlp4Syntax =3D > FreshGram(struct end) >=20 > module B(FreshGram : functor(Unit : sig end) -> Camlp4Syntax) : = Camlp4Syntax =3D > Printers_Ocaml_Make(A(FreshGram)) >=20 > module C(FreshGram : functor(Unit : sig end) -> Camlp4Syntax) : = Camlp4Syntax =3D > Printers_Ocaml_Make(FreshGram(struct end)) > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D >=20 > The error occurs in the last line and says >=20 > Error: Signature mismatch: > Modules do not match: > sig > module Loc : sig type t end > module Ast : sig module Loc : sig type t end end > end > is not included in > Camlp4Syntax > Modules do not match: > sig module Loc : sig type t =3D Ast.Loc.t end end > is not included in > sig module Loc : sig type t =3D Loc.t end end > Modules do not match: > sig type t =3D Ast.Loc.t end > is not included in > sig type t =3D Loc.t end > Type declarations do not match: > type t =3D Ast.Loc.t > is not included in > type t =3D Loc.t >=20 > The error goes away with the following version of = Printers_Ocaml_Make_Sig: >=20 > module type Printers_Ocaml_Make_Sig =3D functor(Syntax : Camlp4Syntax) = ->=20 > sig > module Loc : Loc=20 > with type t =3D Syntax.Loc.t >=20 > module Ast : Camlp4Ast=20 > with type Loc.t =3D Syntax.Ast.Loc.t > and type Loc.t =3D Loc.t > end >=20 > IMHO both Printers_Ocaml_Make_Sig versions should be equivalent: > in the second version the include is spelled out and the module > constraints are expanded into type constraints.=20 >=20 > The error comes back if one changes the order of the type > constaints for module Ast. >=20 >=20 > Bye, >=20 > Hendrik >=20 > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs