ReasonML unit — what does unit mean?

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 = () => {

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.

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store