Browse thread
[Caml-list] tpyping question
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Oleg Trott <oleg_trott@c...> |
| Subject: | Re: [Caml-list] tpyping question |
On Sunday 10 August 2003 09:13 pm, skaller wrote: > type x = [`A | `B of int | `V of float];; > let g (a:x) = a;; > let f a = match a with > > | `A -> g a > > (* | `B _ *) | _ -> g a;; > > Compiles fine, but gives an error if the comments are > removed. > > File "xx.ml", line 4, characters 10-11: > This expression has type [< `A | `B of 'a ] but is here used with type > x = [ `A | `B of int | `V of float ] > The first variant type does not allow tag(s) `V > > I can fix this with a coercion/annotation: > | (`A:x) -> g a > > but that's a bit messy. Of course an annotation on the > argument doesn't work (since such annotations are only > consulted *after* the body type is infered). > > Is there a better way to do this? This is indeed very odd, because the equivalent let f a = match a with `A -> g a | `B _ -> g a | _ -> g a works fine. -- Oleg Trott <oleg_trott@columbia.edu> ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners