March 2019
Intermediate to advanced
208 pages
5h 11m
English
What would happen if we called the avg function but only gave it one argument? Surely we’d get some sort of error:
| | let avg = (a: float, b: float) : float => { |
| | (a +. b) /. 2.0; |
| | }; |
| | |
| | Js.log2("Average of 3 and 4", avg(3.0, 4.0)); |
| | Js.log2("Average of 3?!", avg(3.0)); |
| | code/functions> bsb -make-world |
| | ninja: Entering directory `lib/bs' |
| | [3/3] Building src/Currying.mlast.d |
| | [1/1] Building src/Currying-Simplefunctions.cmj |
| | code/functions> node src/Currying.bs.js |
| | Average of 3 and 4 3.5 |
| | Average of 3?! function (param) { |
| | return avg(3.0, param); |
| | } |
It compiles without errors, and when we run it, we get a function as output ...
Read now
Unlock full access