Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: maf@microsoft.com
Cc: caml-list@inria.fr
Subject: Re: variant filtering
Date: Fri, 18 Feb 2000 23:41:29 +0900	[thread overview]
Message-ID: <20000218234129S.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: Your message of "Thu, 17 Feb 2000 17:15:48 -0800" <783D93998201D311B0CF00805FEAA07B7E90F6@RED-MSG-42>

From: Manuel Fahndrich <maf@microsoft.com>

> 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
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>





  reply	other threads:[~2000-02-21 17:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-18  1:15 Manuel Fahndrich
2000-02-18 14:41 ` Jacques Garrigue [this message]
     [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=20000218234129S.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=maf@microsoft.com \
    /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