From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA06030 for caml-redistribution@pauillac.inria.fr; Mon, 21 Feb 2000 18:10:09 +0100 (MET) Resent-Message-Id: <200002211710.SAA06030@pauillac.inria.fr> Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id DAA24260 for ; Sat, 19 Feb 2000 03:49:45 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id DAA24214 for ; Sat, 19 Feb 2000 03:49:42 +0100 (MET) Received: from tet.kurims.kyoto-u.ac.jp (isdnppp2.kurims.kyoto-u.ac.jp [130.54.16.103]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id LAA21808; Sat, 19 Feb 2000 11:49:39 +0900 (JST) Received: from localhost (localhost [127.0.0.1]) by tet.kurims.kyoto-u.ac.jp (8.9.3/8.9.3) with ESMTP id XAA00597; Fri, 18 Feb 2000 23:41:29 +0900 (JST) (envelope-from garrigue@kurims.kyoto-u.ac.jp) To: maf@microsoft.com Cc: caml-list@inria.fr Subject: Re: variant filtering In-Reply-To: Your message of "Thu, 17 Feb 2000 17:15:48 -0800" <783D93998201D311B0CF00805FEAA07B7E90F6@RED-MSG-42> References: <783D93998201D311B0CF00805FEAA07B7E90F6@RED-MSG-42> X-Mailer: Mew version 1.93 on Emacs 20.4 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20000218234129S.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 18 Feb 2000 23:41:29 +0900 From: Jacques Garrigue X-Dispatcher: imput version 980905(IM100) Resent-From: weis@pauillac.inria.fr Resent-Date: Mon, 21 Feb 2000 18:10:09 +0100 Resent-To: caml-redistribution@pauillac.inria.fr From: Manuel Fahndrich > Variants are great, but pattern matching should filter used cases in the > default branch. This seems to be a dual of the record modification problem > we've seen some time ago on this list. > > Consider the following code: > > > type 'a status = [`Success 'a | `FailureA | `FailureB | `FailureC ];; > > let f () = (`Success "Yeah" :> string status) > > > let g () = > match f () with > `Success s -> `Success 1 > | other -> (other :> int status) Indeed the above code will cause a type error. However, with variants there is a workaround: let g () = match f () with `Success s -> `Success 1 | `FailureA | `FailureB | `FailureC as other -> other Compared to Pottier's Wallace (or Pessaux's exceptions), you have to explicitely give the list of the cases matched by other. Still this will produce the same code as your example would have (had it be typable). Originally, this was a design choice to avoid having to handle specifically row variables: now you cannot name them, but only the variant type containing them. This means that two different variant types cannot share the same row variable, as would be needed in your example. With the conjunctive typing in ocaml 2.99 variants, there may also be new theoretical problems for an approach where rows can be shared. I did not really check. Jacques --------------------------------------------------------------------------- Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp JG