March 2019
Intermediate to advanced
208 pages
5h 11m
English
All the functions we’ve written so far have been fully written out. Here, for example, is a function that squares its argument:
| | let sqr = (x) => { |
| | x * x; |
| | }; |
This function doesn’t take advantage of any of ReasonML’s syntactic sugar. Syntactic sugar is syntax that makes programs easier to read or write, thus making your life sweeter. If a function has only one parameter, you don’t need to enclose it in parentheses. If there’s only one expression in the body of the function, you don’t need the braces. You’d write the function in its most compact form this way:
| | let sqr = x => x * x; |
Perhaps you’d like to keep your code as compact as possible, but you don’t want to waste neurons wondering ...
Read now
Unlock full access