From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 7FD2F7F02D for ; Tue, 21 Oct 2014 09:49:51 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of thomas.braibant@gmail.com) identity=pra; client-ip=209.85.212.181; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="thomas.braibant@gmail.com"; x-sender="thomas.braibant@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of thomas.braibant@gmail.com designates 209.85.212.181 as permitted sender) identity=mailfrom; client-ip=209.85.212.181; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="thomas.braibant@gmail.com"; x-sender="thomas.braibant@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f181.google.com) identity=helo; client-ip=209.85.212.181; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="thomas.braibant@gmail.com"; x-sender="postmaster@mail-wi0-f181.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: At0BAI4ORlTRVdS1m2dsb2JhbABchDkEgwLRZQcWAREBAQEBAQYLCwkULoQbEQQZARseAxIQDwImAiQBEQEFASIbGogIAQMRoAKDHW6LMIFygxCIbAoZJw1nhW0BBQ6BHpIjgVQFkwiKUpQtGCmCewELgiY7L4JLAQEB X-IPAS-Result: At0BAI4ORlTRVdS1m2dsb2JhbABchDkEgwLRZQcWAREBAQEBAQYLCwkULoQbEQQZARseAxIQDwImAiQBEQEFASIbGogIAQMRoAKDHW6LMIFygxCIbAoZJw1nhW0BBQ6BHpIjgVQFkwiKUpQtGCmCewELgiY7L4JLAQEB X-IronPort-AV: E=Sophos;i="5.04,760,1406584800"; d="scan'208";a="102159872" Received: from mail-wi0-f181.google.com ([209.85.212.181]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 21 Oct 2014 09:49:51 +0200 Received: by mail-wi0-f181.google.com with SMTP id hi2so1007155wib.2 for ; Tue, 21 Oct 2014 00:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=r1FdErgfFGRhC6RS0aNc8hI/KI/yE7TKq3ebT7JV3n4=; b=FihCc78MCOqd+wioXFWeRyaZu3lpn9HbYDJpHkx/IRTwerulDRPPhrL6hfc/CgFmS5 dJY9epLYPs3O06qBxBRBxHSVr+00LPWZGkKbIvGE7igh/LcaELEAXUYe8B6fg79vcCSX /pVx8rW4VzBMxb+CUpz6za3CxuglE342EnODrt9L+7SSPiO5kQgQEuSQhswe9RncNsfw uLt4INeGEDgP8CMg/UjkBJFD+d62Szne7l22zTmhSheCvrc3LEuzLBmZsXjt5rDb30AY yxrVGAJsmQN651qOiisqRKm7wG2l7iCDSK9nwNPsxHkW4uVdMXt01JJOpbdycPWwMV68 luKQ== X-Received: by 10.180.219.106 with SMTP id pn10mr27074978wic.63.1413877791070; Tue, 21 Oct 2014 00:49:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.82.39 with HTTP; Tue, 21 Oct 2014 00:49:30 -0700 (PDT) From: Thomas Braibant Date: Tue, 21 Oct 2014 09:49:30 +0200 Message-ID: To: OCaML Mailing List Content-Type: text/plain; charset=UTF-8 Subject: [Caml-list] First class modules sub-typing Hi list, I am slightly puzzled by a type-error related to first class modules. I am basically defining two types (see full example below) ``` type t = (module A) type 'a s = (module A with type I.t = 'a) ``` and I expect a value of type `'a s` can be coerced to a value of type t. However, this is obviously not the case because I get the following error message, and I wonder why. ``` (* Error: This expression has type a s = (module A with type I.t = a) *) (* but an expression was expected of type t = (module A) *) ``` Is there a common pattern to deal with this situation? Any pointers appreciated. Best, Thomas (* Full example *) module type IN = sig type t val of_string : string -> t val to_string : t -> string end module type A = sig module I : IN val v : string end type t = (module A) type 'a s = (module A with type I.t = 'a) let test1 : t -> string = fun (module T) -> T.v (* let test2 : 'a s -> string = fun (module T) -> T.v The type of this packed module contains variables: 'a s *) let test3 (type a) : a s -> string = fun (module T) -> T.v let test4 (type a) : a s -> string = fun t -> test1 t (* Error: This expression has type a s = (module A with type I.t = a) *) (* but an expression was expected of type t = (module A) *) module A1 : A = struct module I : IN = struct type t = int let of_string = int_of_string let to_string = string_of_int end let v = "A1" end let _ = test1 (module A1) (* OK *) let _ = test3 (module A1) (* OK *)