Syntax Lookup

Enter some language construct you want to know more about.
This is a labeled argument.

When declaring a function, arguments can be prefixed with ~ which means that they can and need to be called by their name, not the argument position. This is especially useful to differentiate them more easily if they are of the same type.

Example

ReScriptJS Output
let calculateDistance = (~x1, ~y1, ~x2, ~y2) => {
  Math.sqrt((x1 -. x2) ** 2. +. (y1 -. y2) ** 2.)
}

calculateDistance(~x1=6., ~y1=8., ~x2=3., ~y2=4.)

Labeled arguments can be provided in any order:

ReScriptJS Output
calculateDistance(~x1=6., ~x2=3., ~y1=8., ~y2=4.)

This also works together with partial application:

ReScriptJS Output
let calcY = calculateDistance(~x1=6., ~x2=3., ...)
calcY(~y1=8., ~y2=4.)

References