# Polymorphic variant being generalised

**URL:** <https://discuss.ocaml.org/t/polymorphic-variant-being-generalised/6083>\
**Category:** Community\
**Tags:** ocaml\
**Created:** [July 12, 2020, 10:45pm UTC](https://discuss.ocaml.org/t/polymorphic-variant-being-generalised/6083 "2020-07-12T22:45:50Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![gasche](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/gasche/32/4_2.png) [@gasche](https://discuss.ocaml.org/u/gasche)\
**Post date:** [July 13, 2020, 7:49am UTC](https://discuss.ocaml.org/t/polymorphic-variant-being-generalised/6083/3 "2020-07-13T07:49:27Z")

</div>

@jjb’s reply is excellent, but let’s give a couple extra details. Your example boils down to something like:

```auto
apply : (unit -> [> error]) -> [> error])

```

When you write `[> error]`, you have to understand this as a universal quantification: an instance of `[> error]` is any type which contains at least `error` (for example `[error]` or `[error | `Foo | `Bar]`. As with polymorphic type variables in signature, the caller gets to choose the instance they want at function application time. The two separate occurrences of `[> error]` correspond to two distinct/independent quantifications.

So the caller could instantiate this to, for example:

```auto
apply : (unit -> [error | `Foo]) -> [error | `Bar]

```

and clearly this is incorrect (with the “obvious” implementation `fun f -> f ()`): if the function parameter returns ` `Foo`, then the return type must allow ` `Foo`. In other words, the two occurrences of `[> error]` must be instantiated with the same type. This corresponds to the following, less general (and more correct) signature:

```auto
val apply : (unit -> ([> error] as 'a)) -> ([> error] as 'a)

```

which can also be written

```auto
val apply : (unit -> ([> error] as 'a)) -> 'a

```

---

_[View the full topic](https://discuss.ocaml.org/t/polymorphic-variant-being-generalised/6083)._
