ReasonML unit — what does unit mean?

Kevin Simper
1 min readMay 25, 2018

--

In a strongly typed language you need to define what a function returns every time, but sometimes a function does not return something. This is what unit is used for, unit is used to defining when a function does not return anything.

let log = () => {
print_endline("hello");
print_endline("world")
};
log();

Functions always need argument and with reason when you call the function “()” evaluates to “unit” and since the last line in a function is automatically returned the function has also a return type of unit, because print_endline returns “unit”.

So unit can be a bit confusing at the start coming from JavaScript which is a weakly typed language, but once you begin to use it more and understand the basic principals like there always needs type even when nothing is given.

--

--

Kevin Simper
Kevin Simper

Written by Kevin Simper

I really like building stuff with React.js and Docker and also Meetups ❤

No responses yet