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 KAA19235 for caml-redistribution@pauillac.inria.fr; Fri, 18 Feb 2000 10:46:22 +0100 (MET) Resent-Message-Id: <200002180946.KAA19235@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 CAA32184 for ; Fri, 18 Feb 2000 02:15:54 +0100 (MET) Received: from mail5.microsoft.com (mail5.microsoft.com [131.107.3.121]) by nez-perce.inria.fr (8.8.7/8.8.7) with SMTP id CAA18326 for ; Fri, 18 Feb 2000 02:15:52 +0100 (MET) Received: from 157.54.9.108 by mail5.microsoft.com (InterScan E-Mail VirusWall NT); Thu, 17 Feb 2000 17:15:51 -0800 (Pacific Standard Time) Received: by INET-IMC-05 with Internet Mail Service (5.5.2651.58) id ; Thu, 17 Feb 2000 17:15:51 -0800 Message-ID: <783D93998201D311B0CF00805FEAA07B7E90F6@RED-MSG-42> From: Manuel Fahndrich To: "'caml-list@inria.fr'" Subject: variant filtering Date: Thu, 17 Feb 2000 17:15:48 -0800 X-Mailer: Internet Mail Service (5.5.2651.58) Resent-From: weis@pauillac.inria.fr Resent-Date: Fri, 18 Feb 2000 10:46:21 +0100 Resent-To: caml-redistribution@pauillac.inria.fr 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) Status encodes return values that can take a number of different causes, along with a success case which carries an arbitrary value. Function g tries to return an int status in the case where f returns success, and the failure status of f otherwise. % ocamlc -c status.ml This expression cannot be coerced to type int status = [`Success int|`FailureA|`FailureB|`FailureC]; it has type string status = [`Success string|`FailureA|`FailureB|`FailureC] but is here used with type int #status as 'a = 'a The compiler does not filter the Success case out in the default branch of the compiler, which could tell it to give other the type other : [`FailureA | `FailureB | `FailureC ] which could then be coerced to int status. I know that the exception type system of Francois Pessaux does a similar filtering. How hard would it be to add this feature to OCaml? -Manuel