> > > This has been asked for repeatedly. > Sorry, I swear I have searched through Mantis for this :-/ > I admit this could be useful in some cases but there are difficulties. > > One first question is, what are you really asking for? > > If you just want to be able to omit the pattern before "as", > then it is probably doable (not easy, as in your example one has > to detect that while the return type of how_much is open, other cases > cannot happen), but would not add any expressivity. > > As there is already a nice form of "at least" exhaustiveness check, I had the impression that enough information is available at some point (?) let three_is_a_lot_3 x = match how_much x with | `Three -> `A_lot | `Two | `A_lot as any -> any;; ^^^^^^ Error: This pattern matches values of type [< `A_lot | `Three | `Two ] but a pattern was expected which matches values of type [> `A_lot | `One | `Three | `Two ] The first variant type does not allow tag(s) `One If you want the real thing, i.e. the ability to have functions that "skim" > a variant > type, then this gets much more difficult. > > After a few years trying to follow this list, I start to have an idea of what it means when J. Garrigue says that something is difficult :) So, no, the "real thing" is really not worth the complexity. > let remove_Three = function > `Three -> failwith "Three" > | any -> any > > What kind of type should we give to this function? > Probably something like: > > [`Three | 'a] -> [ 'a ] > > Note here that 'a is a new kind of type variable, that can only > be used as a polymorphic variant row variable. > Such type systems have been studied in the literature, and I think > there is even an Haskell extension doing that, but this can easily > get complicated. > > OCaml avoids introducing such new type variables by requiring > that if two types share the same row variable they must be identical. > In particular this rules out the above type. Removing this restriction > would be a major design change. > > Jacques Garrigue