From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p1LLVDPi025196 for ; Mon, 21 Feb 2011 22:31:13 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlABAGJoYk1KfVO2kWdsb2JhbACEH6IYCBUBAQEBCQsKBxEEIKBPiVyCWIRziQkBAQMFgSKDQXYEjBOISDqBFA X-IronPort-AV: E=Sophos;i="4.62,202,1297033200"; d="scan'208";a="91762818" Received: from mail-pv0-f182.google.com ([74.125.83.182]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 21 Feb 2011 22:31:07 +0100 Received: by pvg11 with SMTP id 11so202709pvg.27 for ; Mon, 21 Feb 2011 13:31:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=0jSf0yoNHubz/Sj/3O39TCgyw6c95pD4Hlc8Us5h8l0=; b=INLj0JhuqwWTaE4Qdq/P9is57mAUKBjChfaHppXQlWCKtSALPnJ7A2iFLYRW1woyJL ZfMvFIfrCw4Q2UKzay3HloZp3i30y32u8kl2wpXmkNbRVPjHxZE0PwKIwY1f7bSxsRWV DFYhQdfBkL5zKWgUnu8tK1cRWnuI7xHJin+yY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=WXN3qOkKFblzn8PfjE4W5Kl8laFwdySgMoxwiG35kRRjMkKJO8ZhhoviVQdmLTB/wY ycCqlGqhAGzneDBjcozd6FKsppREL8/PU7ay0SUwTg1z/K2HgVn035fDOirTae/OHVFe BJzsA0Q10JIzGgl9s8DLydWzV+AwofLmdjS08= MIME-Version: 1.0 Received: by 10.142.58.5 with SMTP id g5mr1538607wfa.186.1298323865706; Mon, 21 Feb 2011 13:31:05 -0800 (PST) Sender: daniel.c.buenzli@gmail.com Received: by 10.142.127.3 with HTTP; Mon, 21 Feb 2011 13:31:05 -0800 (PST) In-Reply-To: References: <878199.20657.qm@web111516.mail.gq1.yahoo.com> Date: Mon, 21 Feb 2011 22:31:05 +0100 X-Google-Sender-Auth: AvLf4rlsqF6CY1h_y3rt8GruYaU Message-ID: From: =?UTF-8?Q?Daniel_B=C3=BCnzli?= To: Dario Teixeira Cc: caml-list@inria.fr Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Constraining abstract type to be of a given subtype > In fact it does compile but I don't think it does what you want > because the 'a is completly unrelated to the `A in Foo1.kind_t Oh well it's always the same error : when you are doing phantom types, the type with phantoms should be abstract. See below. Daniel module Kind: sig type t = [ `A | `B | `C ] val to_string: t -> string end = struct type t = [ `A | `B | `C ] let to_string = function | `A -> "A" | `B -> "B" | `C -> "C" end module type FOO = sig type custom_t type 'a kind_t constraint 'a = [< Kind.t] type 'a t = int * custom_t * 'a kind_t val make: int -> custom_t -> 'a kind_t -> 'a t val string_of_custom: custom_t -> string val string_of_kind: 'a kind_t -> string val kind_to_kind : 'a kind_t -> Kind.t end module Foo1 : sig type custom_t type 'a kind_t constraint 'a = [< Kind.t] type 'a t = int * custom_t * 'a kind_t val make_custom : float -> custom_t val make: int -> custom_t -> 'a kind_t -> 'a t val string_of_custom: custom_t -> string val string_of_kind: 'a kind_t -> string val kind_of_kind : ([ `A ] as 'a) -> 'a kind_t val kind_to_kind : 'a kind_t -> Kind.t end = struct type custom_t = float type 'a kind_t = [`A] constraint 'a = [< Kind.t] type 'a t = int * custom_t * 'a kind_t let make_custom f = f let make id custom kind = (id, custom, kind) let string_of_custom = string_of_float let string_of_kind k = Kind.to_string (k :> Kind.t) let kind_of_kind k = k let kind_to_kind k = (k :> Kind.t) end let (v : [`A] Foo1.t) = Foo1.make 2 (Foo1.make_custom 2.) (Foo1.kind_of_kind `A) (* Should not typecheck let (v : [`B] Foo1.t) = Foo1.make 2 (Foo1.make_custom 2.) (Foo1.kind_of_kind `A) *) module FOOCheck = (Foo1 : FOO)