While Reason's variant types are conceptually simple, much of their power comes from the ability to use them with pattern matching and exhaustivity checking. Reason also provides a more powerful, but also more complex sum type, called polymorphic variants. As the name suggests, these variants are more flexible than regular variants. Here are a few things that we can do with polymorphic variants, but not with regular variants:
- Create values without defining the types beforehand, letting the compiler infer the type
- Compose multiple sets of variant cases together
- Define functions that handle at least a set of variant cases as input
- Define functions that output at most a set of variant cases as output
In a sense, we can think of polymorphic variants as being related to regular variants in the same way that objects are related to records. They are,...