From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 2FC4FBC57 for ; Fri, 14 May 2010 17:49:44 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApsEAMoN7UuFBoIF/2dsb2JhbACeaa9RjXcBBIUQg0I X-IronPort-AV: E=Sophos;i="4.53,231,1272837600"; d="scan'208";a="51176760" Received: from rabbit.math.nagoya-u.ac.jp (HELO mailhost.math.nagoya-u.ac.jp) ([133.6.130.5]) by mail2-smtp-roc.national.inria.fr with ESMTP; 14 May 2010 17:49:43 +0200 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id D07C5B641; Sat, 15 May 2010 00:49:40 +0900 (JST) Received: from mailhost.math.nagoya-u.ac.jp (camel-172 [172.16.254.4]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 8DF2488B1; Sat, 15 May 2010 00:49:40 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=math.nagoya-u.ac.jp; h= date:message-id:to:cc:subject:from:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=alpha; bh=jpezxv8X3d+ovC8C5CdBD990OJ0=; b=O0RczkDrshA5R3lgF7yO5sRBS2ZL M8vfdL1J7FgTJwmwz5H1ynsU3JFFZ7hn7rFmG5JYGjs4JA0jxrBPTdE1Ba5fsyBr Tdwxg61C8DYHPtQqCvVFMdIp/hENHUxb6vZ3OaBwJF7jMIvdrRLxTL0kV5TauUkE O5ouvaNswfEWdrI= DomainKey-Signature: a=rsa-sha1; h=Received:Date:Message-Id:To:Cc:Subject:From:In-Reply-To:References:X-Mailer:Mime-Version:Content-Type:Content-Transfer-Encoding; b=2xNtFtd3bYgxXeJYMawCc6bhB2XioadXxI1MREQDB0BeA+7Bj8C3rOaa9zt6sFBEzYRJii6F/N89Of+aIMfTgWdONAwysyFaS16hCP8Tk4IbxaqKJJfI27i5pRbxXOaG2zCkQ3hEVEfECWZ7vzV8+3exe5DU9MZsfvnKN7iT1DY=; c=nofws; d=math.nagoya-u.ac.jp; q=dns; s=alpha Received: from localhost (bsdserver02 [172.16.249.2]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 5EC2388B0; Sat, 15 May 2010 00:49:40 +0900 (JST) Date: Sat, 15 May 2010 00:49:40 +0900 (JST) Message-Id: <20100515.004940.200940107.garrigue@math.nagoya-u.ac.jp> To: philippe.veber@googlemail.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] Closed variants, type constraints and module signature From: Jacques Garrigue In-Reply-To: References: X-Mailer: Mew version 6.3 on Emacs 22.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; variants:01 sig:01 val:01 sig:01 val:01 struct:01 mismatch:01 polymorphic:01 caml-list:01 precisely:01 constraint:01 constraint:01 variant:02 define:02 modules:02 From: Philippe Veber > I'd like to define a type with a variable that is constrained to accept only > polymorphic variant types included in a given set of tags. That is how I > believed one should do : > > Objective Caml version 3.11.2 > > # type 'a t = 'a constraint 'a = [< `a | `b ];; > type 'a t = 'a constraint 'a = [< `a | `b ] > > But I stumbled upon the following problem, when trying to use this > definition > > > # module type S = sig > val v : 'a t > end;; > module type S = sig val v : [< `a | `b ] t end > > # module I : S = struct > let v = `a > end;; > > Error: Signature mismatch: > Modules do not match: sig val v : [> `a ] end is not included in S > Values do not match: > val v : [> `a ] > is not included in > val v : [< `a | `b ] t > > Does anyone know why the definition of module I is rejected ? And if this is > the intended behavior, why does the following work ? > > # let v : 'a t = `a > ;; > val v : [< `a | `b > `a ] t = `a But it doesn't really work! More precisely, the type [< `a | `b > `a ] t is an instance of 'a t, not 'a t itself, an a module interface should give a type at most as general as the implementation. In your case, you should simply write type t = [`a | `b] since you don't know what v may be. Jacques Garrigue