# Polymorphic variant representation

**URL:** <https://discuss.ocaml.org/t/polymorphic-variant-representation/5904>\
**Category:** Learning\
**Created:** [June 3, 2020, 7:26am UTC](https://discuss.ocaml.org/t/polymorphic-variant-representation/5904 "2020-06-03T07:26:32Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![recoules](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/recoules/32/1742_2.png) [@recoules](https://discuss.ocaml.org/u/recoules)\
**Post date:** [June 3, 2020, 9:49am UTC](https://discuss.ocaml.org/t/polymorphic-variant-representation/5904/5 "2020-06-03T09:49:57Z")

</div>

> [@smolkaj](#):
>
> This is not really in scope for your question, but another disadvantage of polymorphic variants is that their types rules are more complicated.

It is true, but they allow more flexibility and I expect them to be easier to learn, from a beginner point of view, than GADT.

> [@vlaviron](#):
>
> There’s an advantage to polymorphic variants that you have not mentioned: you can pass their values from two different types without the cost of a conversion (if the types are compatible).

You are right. It is exactly why I am looking for polymorphic variant. In this different topic [Sum types: sub- & super-type](https://discuss.ocaml.org/t/sum-types-sub-super-type/5894), I present two use cases where polymorphic variants perform well but, are maybe too powerful for what I want to do.

> [@yallop](#):
>
> > [@recoules](#):
> >
> > Also, I am wondering, as polymorphic variants use `hash` function, is a collision possible for two distinct variants?
> 
> Yes:

Oh… so it is possible, but is caught by the compilation.  
I am curious, is it an already known collision example, or did you find it just for me? 🙂

---

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