From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p1LLoIMs025732 for ; Mon, 21 Feb 2011 22:50:18 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlABAE9tYk3RVaA2kGdsb2JhbACEH6IYCBUBAQEBCQkMBxEEIKBYiVyCWIR3iQkBAQMFgSKDQXYEjBOISDqBFA X-IronPort-AV: E=Sophos;i="4.62,202,1297033200"; d="scan'208";a="76327500" Received: from mail-pw0-f54.google.com ([209.85.160.54]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 21 Feb 2011 22:49:49 +0100 Received: by pwj8 with SMTP id 8so573661pwj.27 for ; Mon, 21 Feb 2011 13:49:47 -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=nfOMHuWJ3MkQ6Uvn9nnru3mt9uHJ9EkFml8Nr0rPO00=; b=bNWXObKJFCxCEtoDGW8TmrAeFDxWc+oxAdSGTqN3NqKimxwgGl2jZIs9OpB4DRsUMw kHvne67KovVdGXtozqE/8wiubc53p3qXcZHOuqsj8h2vEkFar3KDkNINbYVKSkuiT4P3 Gzk/ImqVLEIACONxnrftWOP3mzzPd1zjaRnJg= 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=lzSfOluPe1zsP8U517cFTpz/uq+r0616mAIhgGPnxQMalflCwj7LHoCzLtxWCidywZ TPgGBJX+QPhz7fIUkZpoScDW32H3j5kaQiURnjEOi9PXEA89CN10XsQ++gKwliFoG4IY ACiQgfKm4mp78gw3zzOtKQTTZ19/Fo0+MzPnw= MIME-Version: 1.0 Received: by 10.142.58.5 with SMTP id g5mr1552341wfa.186.1298324987574; Mon, 21 Feb 2011 13:49:47 -0800 (PST) Sender: daniel.c.buenzli@gmail.com Received: by 10.142.127.3 with HTTP; Mon, 21 Feb 2011 13:49:47 -0800 (PST) In-Reply-To: References: <878199.20657.qm@web111516.mail.gq1.yahoo.com> Date: Mon, 21 Feb 2011 22:49:47 +0100 X-Google-Sender-Auth: 6q7M0_c6lx_XKE0sC9ZoLIvs0Zk 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 Ok last message I promise. I don't know exactly what you want but you may prefer the following FOO (see the signature of kind_to_kind) : 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 -> 'a end In that case the idea is that each implementer declares kind as : type 'a kind = 'a constraint 'a = [< Kind.t] but controls which 'a it will actually allow via the kind_of_kind function (better names to be found) : module FooAB : 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 | `B] as 'a) -> 'a kind_t val kind_to_kind : 'a kind_t -> 'a 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 end let (v : [`A | `B] FooAB.t) = FooAB.make 2 (FooAB.make_custom 2.) (FooAB.kind_of_kind `A) let (v : [`A | `B] FooAB.t) = FooAB.make 2 (FooAB.make_custom 2.) (FooAB.kind_of_kind `B) let (k : [`A |`B]) = FooAB.kind_to_kind (FooAB.kind_of_kind `A) (* Should not typecheck let v = FooAB.make 2 (FooAB.make_custom 2.) (FooAB.kind_of_kind `C) *) module FOOCheck = (FooAB : FOO)