caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Manuel Fahndrich <maf@microsoft.com>
To: "'caml-list@inria.fr'" <caml-list@inria.fr>
Subject: variant filtering
Date: Thu, 17 Feb 2000 17:15:48 -0800	[thread overview]
Message-ID: <783D93998201D311B0CF00805FEAA07B7E90F6@RED-MSG-42> (raw)


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



             reply	other threads:[~2000-02-18  9:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-18  1:15 Manuel Fahndrich [this message]
2000-02-18 14:41 ` Jacques Garrigue
     [not found] <783D93998201D311B0CF00805FEAA07B7E9101@RED-MSG-42>
2000-02-21  2:44 ` Jacques Garrigue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=783D93998201D311B0CF00805FEAA07B7E90F6@RED-MSG-42 \
    --to=maf@microsoft.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).