# Understanding polymorphic variants

**URL:** <https://discuss.ocaml.org/t/understanding-polymorphic-variants/13500>\
**Category:** Learning\
**Tags:** polymorphic-variants\
**Created:** [November 26, 2023, 5:09am UTC](https://discuss.ocaml.org/t/understanding-polymorphic-variants/13500 "2023-11-26T05:09:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mobileink](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mobileink/32/3295_2.png) [@mobileink](https://discuss.ocaml.org/u/mobileink)\
**Post date:** [November 26, 2023, 5:09am UTC](https://discuss.ocaml.org/t/understanding-polymorphic-variants/13500/1 "2023-11-26T05:09:36Z")

</div>

[Starting a new thread on grounds that [New Draft Tutorial on Polymorphic Variants](https://discuss.ocaml.org/t/new-draft-tutorial-on-polymorphic-variants/13485) is for feedback on the tutorial]

Exploring polymorphic variants I tried this:

```auto
 # let f = function
| `Cat -> "pet"
| `Dog -> "pet"
| 99 -> "other" ;;
Error: This pattern matches values of type int
       but a pattern was expected which matches values of type [? `Cat | `Dog]

```

I have not come across `[? ...]` in the documentation. What does it mean? (I expected 99 to cause an error, but the message surprised me.)

Gregg

---

<div class="post-metadata">

**Author:** ![cuihtlauac](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cuihtlauac/32/3638_2.png) [@cuihtlauac](https://discuss.ocaml.org/u/cuihtlauac)\
**Post date:** [November 26, 2023, 7:58am UTC](https://discuss.ocaml.org/t/understanding-polymorphic-variants/13500/2 "2023-11-26T07:58:41Z")

</div>

Isn’t it that the thing that shall not be named couldn’t decide if the pattern matching creates a closed or an open polymorphic variant and, therefore, prints a question mark?

---

<div class="post-metadata">

**Author:** ![octachron](https://avatars.discourse-cdn.com/v4/letter/o/49beb7/32.png) [@octachron](https://discuss.ocaml.org/u/octachron)\
**Post date:** [November 26, 2023, 9:04am UTC](https://discuss.ocaml.org/t/understanding-polymorphic-variants/13500/3 "2023-11-26T09:04:04Z")

</div>

The `?` symbol means that it is unknown if the polymorphic variant type should be open like in

```ocaml
let f = function
| `Cat -> ()
| `Dog -> ()
| _ -> ()

```

where `f` has type `[> `Cat | `Dog] -> unit` or closed like in

```ocaml
let f = function
| `Cat -> ()
| `Dog -> ()

```

where the type of `f` is ` [< `Cat | `Dog] -> unit`.  
Since the typing of the pattern matching was interrupted by the `99` type error, it is not possible to decide between the two cases, leading thus to the type `[? `Cat | `Dog]` appearing in the error message.  
In a fully unicode compatible word, I may propose to replace `?` with `[≶? `Cat | `Dog]`
