Using Variables and Doing Arithmetic in ReasonML

Now that you know your way around compiling and running a program, let’s create a program that uses variables and performs calculations. Specifically, we’ll write a program that calculates a total price, given a quantity and per-unit price. From this point on, we’ll be using examples from the code samples accompanying this book, downloadable from the Pragmatic Programmers website.

 let​ ​qty​ = 7;
 let​ ​price​ = 15;
 let​ ​total​ = ​qty​ * ​price​;
 Js​​.log2​(​"The total price is $"​, ​total​);

This code introduces variables. Variable names in ReasonML, like those in many other programming languages, must begin with a lowercase letter and may be followed ...

Get Web Development with ReasonML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.