March 2019
Intermediate to advanced
208 pages
5h 11m
English
In JavaScript, we could have solved the problem of bad input for shirtSizeOfString by returning null or undefined, but that leads to all manner of difficulties. What we really want is a way to handle invalid data in a type-safe manner.
ReasonML solves the problem with a built-in variant data type named option. If you were to write it yourself, it would look like this:
| | type option('a) = |
| | | Some('a) |
| | | None; |
This is a parametric data type (see What’s a Parametric Data Type? for details) where ’a is a type variable. The leading single quote is required for type variables.
Read now
Unlock full access