Syntax Lookup

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

Labeled arguments, i.e. arguments that are prefixed with ~, can be suffixed with =? to denote that they are optional. Thus, they can be omitted when calling the function.

Example

ReScriptJS Output
let print = (text, ~logLevel=?) => {
  switch logLevel {
  | Some(#error) => Console.error(text)
  | _ => Console.log(text)
  }
}

print("An info")
print("An error", ~logLevel=#error)

Optional labeled arguments can also hold a default value.

ReScriptJS Output
let print = (text, ~logLevel=#info) => {
  switch logLevel {
  | #error => Console.error(text)
  | #warn => Console.warn(text)
  | #info => Console.log(text)
  }
}

print("An info")
print("A warning", ~logLevel=#warn)

References