From the course: ReasonML: First Look
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Functions and annotations - ReasonML Tutorial
From the course: ReasonML: First Look
Functions and annotations
- [Man] Reason is a functional programming language. So let's investigate writing functions. Here's the generic model for a function in Reason. You use let to bind the function name to the function definition, which begins with the list of parameters, a thick arrow, and the body of the function in braces. You end the function definition with a semicolon, just as you would for a statement like let x equal five, by the way, the slash star and star slash are how you do comments in ReasonML. Let's look at a function for calculating the arithmetic mean of three numbers. You can see that Reason has correctly inferred the data types of the parameters and the return value. Everything's a float. Unlike JavaScript, there's no return statement, the value of the last expression evaluated in the body of the function, becomes the function result. Here's a quick test of the function where Js.log, register the terminal. We get the mean of…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.