March 2019
Intermediate to advanced
208 pages
5h 11m
English
In a program of any significant length, we’ll eventually end up passing option values through a series of functions, some of which accept and/or return option values, and some that don’t. Consider these functions:
| | let toFloat = (str: string) : option(float) => { |
| | let result = (Js.Float.fromString(str)); |
| | if (Js.Float.isNaN(result)) { |
| | None |
| | } else { |
| | Some(result) |
| | } |
| | }; |
| | |
| | let cube = (x: float) : float => x *. x *. x; |
| | |
| | let reciprocal = (x: float) : option(float) => { |
| | if (x !== 0.0) { |
| | Some(1.0 /. x) |
| | } else { |
| | None |
| | } |
| | }; |
We’d like to stitch these together into a program that performs the following ...
Read now
Unlock full access