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 p1LJdxjM021810 for ; Mon, 21 Feb 2011 20:39:59 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlABACJOYk3RVdS2kGdsb2JhbACEH6IWCBUBAQEBCQkMBxEEIKBXiVyCWIRkiQkBAQMFgSKDQXYEjBOISDqBFA X-IronPort-AV: E=Sophos;i="4.62,201,1297033200"; d="scan'208";a="88422089" Received: from mail-px0-f182.google.com ([209.85.212.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 21 Feb 2011 20:39:55 +0100 Received: by pxi20 with SMTP id 20so350654pxi.27 for ; Mon, 21 Feb 2011 11:39:53 -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=93/25BswA8t1zMTPeksJKMscmG/tveZrcngZJAXHWJo=; b=tPUHw0lj9MQB1tMRYvdWJmWJqsP4cIcFQPUuwLlrA7HGxcfWZKr3DzagDtFaCKInBN XIvwuGqvlyZlOF3tlNOZ+jPShclWmYnBFxs4LPONUujN5YVblocWriak6e1acgcETldR zym2oXalaqn2oQ4W39z15xiB75Zlkooy6XQlA= 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=oLAbIwt6L8ua15rs1Ua/EWa0quTPsqTagVUnsJQYJPnv2r7ccJKPFO5ZvL9XPbuv0m ql4FcP6USI+/CDE7r8lAC7cw8gM3kBAXjBXbrrjdKYOMIfsWpCAwzNTvfRV7kGInxxQO SgrXlDiiLw/QDb0uW27M+HmAD1ks+CKPDQzXw= MIME-Version: 1.0 Received: by 10.142.58.5 with SMTP id g5mr1456671wfa.186.1298317193502; Mon, 21 Feb 2011 11:39:53 -0800 (PST) Sender: daniel.c.buenzli@gmail.com Received: by 10.142.127.3 with HTTP; Mon, 21 Feb 2011 11:39:53 -0800 (PST) In-Reply-To: <982043.53335.qm@web111502.mail.gq1.yahoo.com> References: <20110221170702.GJ25151@localhost> <982043.53335.qm@web111502.mail.gq1.yahoo.com> Date: Mon, 21 Feb 2011 20:39:53 +0100 X-Google-Sender-Auth: yodVQ4YFtDyaZTo2b0Q3oRakdOk 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 I'm just wondering. Abstraction is about hiding type representation. Variant subtyping is a kind of structural subtyping and is thus about type representation. So constraining an abstract type to be of a given structural subtype seems contradictory. The only way I see to type what you want is to make FOO.kind_t abstract. This doesn't ensure that the implementation of 'a kind_t is a subtype of Kind.t itself. However if your goal is some kind of phantom type constraints, it will do the job. And you can still require a function to convert 'a kind to Kind.t. See the code below. Best, 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: FOO = 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 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_to_kind k = (k :> Kind.t) end