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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 1DD90BC58 for ; Fri, 14 May 2010 17:18:00 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhwDAIcG7UvRVdnUe2dsb2JhbACdcAgVAQEWIgMfrx4BBY10AQSFEA X-IronPort-AV: E=Sophos;i="4.53,229,1272837600"; d="scan'208";a="59362071" Received: from mail-gx0-f212.google.com ([209.85.217.212]) by mail1-smtp-roc.national.inria.fr with ESMTP; 14 May 2010 17:17:59 +0200 Received: by gxk4 with SMTP id 4so1523797gxk.2 for ; Fri, 14 May 2010 08:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:mime-version:received:from:date :message-id:subject:to:content-type; bh=B/ApanssXCwiykcT6llHJiFSUIDaqhiAsLbXWP6fMYY=; b=cycTEM2W48UZpjiVtyQluqOZO67W0JGSUXuoCh0egZbFWxOd1EKJ5RssZO0FYD0rUB oVVMllo/WTw+3MnWZsWqOK4LSv0k2c0e64rYNzEDPdnoQ6s8m9nZUC7dNb36ADqn4VM5 rVUzLtQ90W9F9nt+czzPNUwLuBfQIyHAMftsY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=XCtNeuduPHqHfORhEuBvRmZqiF5K11JRGF6ZT9edx+GgFNiPoIO0Vl5I0kI2P//SyU 3m4Z3AwKb+Kl1Qnzb62U14d2RErz/J7tJLMpA0ehKji1IEDVKf1beyclaSItMrCz5EiS kPSGp+s7lVT3+bbCXVnuWzjT7wYiiTaxQbttU= Received: by 10.101.10.16 with SMTP id n16mr1423914ani.92.1273850278391; Fri, 14 May 2010 08:17:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.109.11 with HTTP; Fri, 14 May 2010 08:17:37 -0700 (PDT) From: Philippe Veber Date: Fri, 14 May 2010 17:17:37 +0200 Message-ID: Subject: Closed variants, type constraints and module signature To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=0016e6d2659557400f04868f618f X-Spam: no; 0.00; variants:01 sig:01 val:01 sig:01 val:01 struct:01 mismatch:01 struct:01 mismatch:01 W8:98 W8:98 monospace:98 monospace:98 W6:98 W6:98 --0016e6d2659557400f04868f618f Content-Type: text/plain; charset=ISO-8859-1 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 Philippe. --0016e6d2659557400f04868f618f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I'd like to define a type with a variable that is co= nstrained to accept only polymorphic variant types included in a given set = of tags. That is how I believed one should do :

=A0=A0=A0=A0=A0=A0=A0 Objective Caml version 3.11.2

# type '= a t =3D 'a constraint 'a =3D [< `a | `b ];;
type 'a t =3D= 'a constraint 'a =3D [< `a | `b ]


But I stumbled upo= n the following problem, when trying to use this definition


# module type S =3D sig
=A0 val v : 'a t=A0=A0=A0
end;;
module type S =3D sig val v : [&= lt; `a | `b ] t end

# module I : S =3D struct
=A0=A0=A0 let v =3D= `a
=A0 end;;

=A0 Error: Signature mismatch:
=A0=A0=A0=A0=A0= =A0 Modules do not match: sig val v : [> `a ] end is not included in S =A0=A0=A0=A0=A0=A0 Values do not match:
=A0=A0=A0=A0=A0=A0=A0=A0 val v := [> `a ]
=A0=A0=A0=A0=A0=A0 is not included in
=A0=A0=A0=A0=A0=A0= =A0=A0 val v : [< `a | `b ] t

Does anyone kno= w why the definition of module I is rejected ? And if this is the intended = behavior, why does the following work ?

# let v : 'a t =3D `a=A0 ;;
val v : [< `a | `b > `a ] t =3D `a


Philippe.


--0016e6d2659557400f04868f618f--