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 nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 375DDBB81 for ; Sun, 19 Mar 2006 15:24:12 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k2JEOBAH012942 for ; Sun, 19 Mar 2006 15:24:11 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA23681 for ; Sun, 19 Mar 2006 15:24:10 +0100 (MET) Received: from grymling.conjury.org (grymling.conjury.org [69.12.155.90]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k2JEO9iC020224 for ; Sun, 19 Mar 2006 15:24:10 +0100 Received: from localhost (localhost [127.0.0.1]) by grymling.conjury.org (Postfix) with ESMTP id 5C411A338F; Sun, 19 Mar 2006 06:24:05 -0800 (PST) Received: from grymling.conjury.org ([127.0.0.1]) by localhost (grymling.conjury.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 24367-09; Sun, 19 Mar 2006 06:23:59 -0800 (PST) Received: from [10.0.1.200] (station.conjury.org [69.12.155.91]) by grymling.conjury.org (Postfix) with ESMTP id 224E4A3370; Sun, 19 Mar 2006 06:23:59 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v746.3) Content-Type: text/plain; charset=WINDOWS-1252; delsp=yes; format=flowed Message-Id: <05965C1A-F9E5-4E62-8D74-C8314D55425C@conjury.org> Cc: The Caml Trade Reply-To: ocaml-beginners@yahoogroups.com Content-Transfer-Encoding: quoted-printable From: j h woodyatt Subject: Re: Typing problem Date: Sun, 19 Mar 2006 06:23:57 -0800 To: =?ISO-8859-1?Q?Daniel_B=FCnzli?= X-Mailer: Apple Mail (2.746.3) X-Virus-Scanned: by amavisd-new at conjury.org X-Miltered: at nez-perce with ID 441D698B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 441D6989.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; woodyatt:01 jhw:01 bunzli:01 buenzli:01 epfl:01 statically:01 ocaml's:01 woodyatt:01 jhw:01 typing:01 typing:01 behaviour:01 short:01 define:01 constraint:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Daniel B=FCnzli > > I would like to define the following types. > >> type u =3D [ `U1 | `U2 ] >> type 'a t =3D [`A of 'a | `B of ([`U1 ] as 'a) ] constraint 'a =3D [< = u ] > > t's parameter is used to statically express constraints in other =20 > parts of the code. My problem is that the constraint on 'a is =20 > downgraded to [`U1] while I would like to be able to write > >> let param : 'a t -> 'a =3D function (`A v | `B v) -> v > > and get the following typing behaviour. > >> let v =3D param (`A `U1) (* should type *) >> let v =3D param (`A `U2) (* should type *) >> let v =3D param (`B `U1) (* should type *) >> let v =3D param (`B `U2) (* should not type *) > > Is it possible to express that in ocaml's type system ? The short answer is no. The reason is that 'a is not the same type =20 in the `A case as in the `B case. Type t really has two type =20 parameters. (Well, it can have only one if this contrived example is =20= fully representative of your code, as I'll describe below). type ('a, 'b) t =3D [ `A of 'a | `B of 'b ] constraint 'a =3D [< u ] constraint 'b =3D [ `U1 ] However, 'b is concrete in your example, so-- if it's fully =20 representative of your code-- you could just do this, and you would =20 still have only one type parameter: type 'a t =3D [ `A of 'a | `B of [ `U1 ] ] constraint 'a =3D [< u ] =97 j h woodyatt