Search⌘ K
AI Features

Labels

Explore how labeled arguments in ReasonML help you assign values to function parameters without relying on their position. Learn to improve code readability and avoid errors by explicitly labeling parameters, and discover how to use different names for labels and parameters for better code management.

The Position of a Parameter

So far in the course, the arguments in a function have had fixed positions. In other words, the order of inputs must be maintained when calling the function.

Here’s an example:

Reason
type superhero = {
realName: string,
heroName: string
};
let createHero = (realName, heroName) => {
realName,
heroName
};
let real = "Bruce Wayne";
let hero = "Batman";
/* Correct Order */
let correctBatman = createHero(real, hero);
Js.log(correctBatman);
/* Incorrect Order */
let incorrectBatman = createHero(hero, real);
Js.log(incorrectBatman);

In line 19, we reversed the order of our parameters, however, since the function was defined with the first ...