Polymorphic Comparison

In this lesson, we'll get familiarized with the concept of polymorphism in ReasonML.

What is Polymorphism?

The meaning behind the intimidating term, “polymorphism”, is really quite simple. Polymorphism refers to a certain method changing its behavior according to different situations.

This can prove very useful as the same method can be used for different purposes. ReasonML also exhibits polymorphism in some cases, and we’ve already been through one of them.

Comparison Operators for Different Types

Consider a comparison operator which always gives us a boolean depending on the condition we specify. How many types can it support? We can compare integers, floats, characters, and even strings!

The operator knows the difference between these types and how to perform comparisons for each type. This is polymorphism at its finest.

Get hands-on with 1200+ tech skills courses.