Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Ord mean in Ramda's type annotation?

Ramda's documentation for clamp states:

clamp

Ord a => a → a → a → a

Restricts a number to be within a range.

Also works for other ordered types such as Strings and Dates.

R.clamp(1, 10, -1) // => 1
R.clamp(1, 10, 11) // => 10
R.clamp(1, 10, 4)  // => 4

I understand what "a → a → a → a" means (a curried function that takes three arguments of the same type and returns a result of the same type as arguments).

What does "Ord" and fat arrow (=>) mean?

like image 922
Pavlo Avatar asked Jan 05 '23 15:01

Pavlo


2 Answers

Jared's answer is great. This just adds a little more perspective from the Ramda side.

Ramda has a long article on its type annotations (disclaimer: I wrote it.) The section on type constraints describes these.

The fat arrow implies that the phrases on the left constrain the description on the right. Ord means that the type is ordered, that is, that it works properly with < and >. This includes built-in types such as Strings, Numbers, and Dates, as well as user types with valueOf methods that give a proper ordering.

like image 74
Scott Sauyet Avatar answered Jan 18 '23 23:01

Scott Sauyet


Ord is an ordered datatype. The fat arrow denotes a precondition for the arguments. In this case, I believe it means that the datatype is constrained to types for which things like < and > are meaningful (in a strongly-typed language you'd get a compile-time error for anything else).

like image 40
Jared Smith Avatar answered Jan 18 '23 23:01

Jared Smith