Browse thread
Re: [Caml-list] Polymorphic variant difference...
- David Allsopp
[
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: | David Allsopp <dra-news@m...> |
| Subject: | Re: [Caml-list] Polymorphic variant difference... |
> Given a polymorphic variant type t with a label `B how does one build
> the type corresponding to t without the label `B.
So that you could write something like:
type t = [ `A | `B | `C ]
let f x =
match x with
`B -> (* x has type t *)
| #(t minus [ `B ]) as x -> (* x has type [ `A | `C ] *)
I end up having to write lots of tedious extra types to achieve that
normally... I'd find a subtraction syntax very handy too.
On a similar subject, am I the only person who finds I often need to take a
fixed polymorphic variant value and coerce it so that it can just accept
more constructors e.g. (seriously contrived example)...
type t = [ `A | `B | `C ]
let f (x : t) =
match x with
`A -> `D
| _ -> (x : t :> [> t ])
Something more concise than (x : t :> [> t ]) would be nice: e.g. (x ::> t)
But perhaps that really is a job for camlp4!
David