September 2017
Beginner to intermediate
396 pages
9h 46m
English
The Either data type has two data constructors and is defined as a sum type as follows:
data Either a b = Left a | Right b
In our recipe, we used Either String Int, where the right value is of the Int type and the left value is of the String type. In many practical examples, the Left value is used as an error value and the Right value is used as an intended result value.
In the function safeDiv, we stored the error value in Left as a String and stored the result in the Right value.
Like Maybe, Either appears in many libraries on package and is a popular choice to represent result values with error, if any.
Read now
Unlock full access