caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: pfitzen@informatik.uni-tuebingen.de
Cc: caml-list@inria.fr
Subject: Re: # and polymorphic variants
Date: Thu, 01 Feb 2001 23:31:10 +0900	[thread overview]
Message-ID: <20010201233110I.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <200102010037.BAA12641@sunstroke.informatik.uni-tuebingen.de>

From: Juergen Pfitzenmaier <pfitzen@informatik.uni-tuebingen.de>

> Dear ocaml users,
> consider the following example:
> 
> type t1 = [ `A of int ];;
> type t2 = [ `B of string ];;
> type t = [ `A of int | `B of string ];;
> 
> let f1 (`A (x : int)) =
> 	print_int x
> and f2 (`B (x : string)) =
> 	print_string x
> and f (x : t) =
> 	match x with
> 	| #t1 -> f1 x      (* this is not allowed !! *)
> 	| #t2 -> f2 x;;
...
> But I would like to see something clean like giving a name to the # pattern
>     ...
> 	match x with
> 	| #t1 y -> f1 y    (* (y : t1) would have the same value as x *)

You were pretty close to the solution !
You just have to write
        match x with
        | #t1 as y -> f1 y
        | #t2 as y -> f2 y

logical, no?

         Jacques



  parent reply	other threads:[~2001-02-02 15:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-01  0:37 Juergen Pfitzenmaier
2001-02-01  9:50 ` Andrzej M. Ostruszka
2001-02-01 14:31 ` Jacques Garrigue [this message]
2001-02-04  8:37   ` Julian Assange
2001-02-02  1:45 ` Brian Rogoff

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=20010201233110I.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=pfitzen@informatik.uni-tuebingen.de \
    /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).