caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* # and polymorphic variants
@ 2001-02-01  0:37 Juergen Pfitzenmaier
  2001-02-01  9:50 ` Andrzej M. Ostruszka
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Juergen Pfitzenmaier @ 2001-02-01  0:37 UTC (permalink / 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




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-02-04 21:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-01  0:37 # and polymorphic variants Juergen Pfitzenmaier
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

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).