From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q21GdFhq021175 for ; Thu, 1 Mar 2012 17:39:15 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am4BAN+kT0/RVdS2kGdsb2JhbABDqxEBiGYIIgEBAQEJCQ0HFAQjghYCLAEbHgMSCQddAREBBQEiNYdkmFiCXQqLcoJxhSA/iHQBBQuNZA4BBAECAQIJAoUgBwIBAxgIHYNCBIhPjGyHGYcZPYQh X-IronPort-AV: E=Sophos;i="4.73,511,1325458800"; d="scan'208";a="133877218" Received: from mail-wi0-f182.google.com ([209.85.212.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 01 Mar 2012 17:39:10 +0100 Received: by wibhn6 with SMTP id hn6so137508wib.27 for ; Thu, 01 Mar 2012 08:39:10 -0800 (PST) Received-SPF: pass (google.com: domain of agarwal1975@gmail.com designates 10.180.107.2 as permitted sender) client-ip=10.180.107.2; Authentication-Results: mr.google.com; spf=pass (google.com: domain of agarwal1975@gmail.com designates 10.180.107.2 as permitted sender) smtp.mail=agarwal1975@gmail.com; dkim=pass header.i=agarwal1975@gmail.com Received: from mr.google.com ([10.180.107.2]) by 10.180.107.2 with SMTP id gy2mr12569911wib.12.1330619950412 (num_hops = 1); Thu, 01 Mar 2012 08:39:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; bh=n5Yr+TmGJjMG1S+682y7FIA7KDNBvE3sTwjO9OphBO0=; b=Dcs/ha4zYN0B+qilVNQcHxPuiZ8dolVKCH/Mg42FbwKw/ntO/TJASrTtPcTI2jxd+V 7pUEGnGbY0ePQ/cnde5K0Z/ZXKVcpoOKku6o05ogSd2SyNaKBUPCOlgJH+SBGCqnDrNt j5MxKukLqQj3JKAeO+qr7y0n4zHVNPF0iU0T0= Received: by 10.180.107.2 with SMTP id gy2mr10075319wib.12.1330619950296; Thu, 01 Mar 2012 08:39:10 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.159.7 with HTTP; Thu, 1 Mar 2012 08:38:50 -0800 (PST) From: Ashish Agarwal Date: Thu, 1 Mar 2012 11:38:50 -0500 Message-ID: To: Caml List Content-Type: multipart/alternative; boundary=e89a8f3b9f6577ef9304ba3119ca Subject: [Caml-list] types not equal when I expect them to be --e89a8f3b9f6577ef9304ba3119ca Content-Type: text/plain; charset=ISO-8859-1 The following code fails to compile: ----- a.ml ---- module Foo = struct module St = struct type t = string let compare = compare end module Map (* : Map.S with type key = St.t *) = Map.Make(St) (* module Map = Map.Make(struct type t = string let compare = compare end) *) end module Bar = struct type t = int Foo.Map.t end module Pack = struct module Foo = Foo module Bar = Bar end open Pack let x : Bar.t = Foo.Map.empty ---- $ ocamlc -c foo.ml File "foo.ml", line 20, characters 16-29: (* refers to Foo.Map.empty on last line *) Error: This expression has type 'a Pack.Foo.Map.t = 'a Map.Make(Pack.Foo.St).t but an expression was expected of type Pack.Bar.t = int Map.Make(Foo.St).t So Pack.Foo and Foo are not compatible. By trial and error, I found two ways to resolve the problem: 1) Provide an explicit signature for Foo.Map (uncomment the provided signature), or 2) Inline the structure passed to Map.Make (comment out first definition of Foo.Map and uncomment the second one) But I don't understand why. Can anyone explain the main points. Thank you. --e89a8f3b9f6577ef9304ba3119ca Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable The following code fails to compile:

----- a.ml ----
module Foo =3D struct
=A0= module St =3D struct type t =3D string let compare =3D compare end

=A0 module Map (* : Map.S with type key =3D St.t *)
=A0 =A0 = =3D Map.Make(St)
=A0=A0
=A0 (* module Map =3D Map.Make(= struct type t =3D string let compare =3D compare end) *)
end

module Bar =3D struct
=A0 type t =3D int Foo.Map.t
end<= /div>

module Pack =3D struct
=A0 module Foo = =3D Foo
=A0 module Bar =3D Bar
end

=
open Pack
let x : Bar.t =3D Foo.Map.empty
----
$ ocamlc -c foo.ml
Fil= e "foo.ml", line 20, characters 16-= 29: (* refers to Foo.Map.empty on last line *)
Error: This expression has type
=A0 =A0 =A0 =A0 =A0'a Pa= ck.Foo.Map.t =3D 'a Map.Make(Pack.Foo.St= ).t
=A0 =A0 =A0 =A0but an expression was expected of type
=A0 =A0 =A0 =A0 =A0Pack.Bar.t =3D int Map.Make(Foo.St).t


So Pack.Foo and Foo are not compat= ible. By trial and error, I found two ways to resolve the problem:

1) Provide an explicit signature for Foo.Map (uncomment th= e provided signature), or
2) Inline the structure passed to Map.Make (comment out first definiti= on of Foo.Map and uncomment the second one)

But I = don't understand why. Can anyone explain the main points. Thank you.

--e89a8f3b9f6577ef9304ba3119ca--