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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id ABE9D7ED26 for ; Thu, 31 May 2012 22:23:55 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtYCABPTx0/RVdW2kGdsb2JhbABEozKPPgSBGQgiAQEBAQkJDQcUBCOCGAEBAQQSAiwBGxILAQMMBgULDQ0hIgERAQUBChIZEhCHWgEDCwuaQQkDjCKCcIRXChknAwpXiHEBBQyLBS6CAoMWA5UYgQ+NBz6EAQ X-IronPort-AV: E=Sophos;i="4.75,693,1330902000"; d="scan'208";a="160798039" Received: from mail-yx0-f182.google.com ([209.85.213.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-MD5; 31 May 2012 22:23:55 +0200 Received: by yenl8 with SMTP id l8so1803975yen.27 for ; Thu, 31 May 2012 13:23:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=+UBsF4/+kRB7XOEeInbdpICXy36CyxKkgA6OVo+9R64=; b=gx5cwAIqDIyQSGsn+M+H3nCrmb3smwLZlkRrMDq8tJO6mHsElq9NVoxXgPoIVqnW+A 9uyWhs3gLhHJcxZsTBGIvYB1e4syfUDMux8NzFxH5WOJn9EscXDyh6kobDYQ4BAMsse/ 6yI924OqGndX+U/r4VtAmBaMRfMPb1eyoAQcV8G8e3uFTWywsjtvodOmIemlS/4ft0ki GzIXMfqkdyyYAx9qkvPHTi2s3CKVWI2GD+EXSMQZ5eJpKAwmekGZZoaA307pos05kqst LiMjRtQ5niV9Tr64aI++WlPQm+2f521k02GzfyxaneHpQi7F30+va0rCnMOA6kSuCaEA Jn9g== Received: by 10.50.213.1 with SMTP id no1mr3575995igc.71.1338495833942; Thu, 31 May 2012 13:23:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.94.39 with HTTP; Thu, 31 May 2012 13:23:13 -0700 (PDT) In-Reply-To: <20120531200555.GA30956@securactive.lan> References: <20120531200555.GA30956@securactive.lan> From: Gabriel Scherer Date: Thu, 31 May 2012 22:23:13 +0200 Message-ID: To: rixed@happyleptic.org Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Strange behavior from type inference after functor application The problem with module C =3D Combi (S) (TypeWithConf (struct let v =3D 1 end)) is that the resulting type has no "name": (struct let v =3D 1 end) can not be part of a type path. On the contrary, TypeWithConf(Conf) has a type t with name TypeWithConf(Conf).t, so C.t can be equal to S.t * TypeWithConf(Conf).t. There would be no such type as S.t * TypeWIthConf(struct let v =3D 1 end).t. The other fix, forcing TypeWithConf to return a signature with (t =3D unit), makes the "naming problem" go away: whatever functor you pass as a parameter (either a path such as "Conf" or a struct exrpession), the resulting type is equal to "unit", you don't have to try to name it from the way it was constructed. On Thu, May 31, 2012 at 10:05 PM, wrote: > Given these definitions: > > -- v1 -- > > module type TYPE =3D sig type t end > > module Combi (S1 : TYPE) (S2 : TYPE) : > =A0 =A0TYPE with type t =3D S1.t * S2.t =3D > struct > =A0 =A0type t =3D S1.t * S2.t > end > > module TypeWithConf (Conf : sig val v : int end) : > =A0 =A0 =A0 =A0TYPE =3D > struct > =A0 =A0type t =3D unit > end > > module S =3D struct type t =3D unit end > > module C =3D Combi (S) (TypeWithConf (struct let v =3D 1 end)) > > let f (x : C.t) =3D fst x > > ----- > > Here, the compiler fails to infer that C.t is indeed the product of two t= ypes > (as stated in the Combi signature), and complains that: > > Error: This expression has type C.t but an expression was expected of typ= e 'a * 'b > (pointing at the argument of fst) > > There is two ways to satisfies it: > > - either, state that the type of TypeWithConf is 'TYPE with type t =3D un= it' > =A0instead of merely 'TYPE' > > - or, more surprisingly, to define the Conf structure as in: > > -- v2 -- > (* ... *) > > module Conf =3D struct let v =3D 1 end > module C =3D Combi (S) (TypeWithConf (Conf)) > > (* ... *) > ----- > > Can someone help me find an explanation to this behavior? > > > > -- > Caml-list mailing list. =A0Subscription 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 >