From: Juergen Pfitzenmaier <pfitzen@informatik.uni-tuebingen.de>
To: undisclosed-recipients:;
Subject: # and polymorphic variants
Date: Thu, 1 Feb 2001 01:37:59 +0100 (MET) [thread overview]
Message-ID: <200102010037.BAA12641@sunstroke.informatik.uni-tuebingen.de> (raw)
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;;
The compiler can't constrain the type t of x to t1/t2 in the call to f1/f2.
And an coercion like in
...
match x with
| #t1 -> f1 (x :> t1)
...
is not allowed. So I see only one solution:
...
match x with
| #t1 -> f1 (Obj.magic(x) :> t1) (* I don't like magic *)
...
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 *)
...
or like
...
match x with
| #t1 -> f1 x (* x is constrained to type t1 *)
...
Any comments ?
-- pfitzen
next reply other threads:[~2001-02-01 8:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-02-01 0:37 Juergen Pfitzenmaier [this message]
2001-02-01 9:50 ` Andrzej M. Ostruszka
2001-02-01 14:31 ` Jacques Garrigue
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=200102010037.BAA12641@sunstroke.informatik.uni-tuebingen.de \
--to=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