ReasonML 101 notes

Reason 101:

variable assignment with let keyword cannot is immutable, but you can set it to mutable by assign to ref()

example JS:

in reason:

for string concat:

array in ReasonML is using [|”a”, “b”, “c”|] /* | = pipe symbol */

and

list is immutable.

in list you can assign a new list like so,

Array are really good at random access indexing and accessing
list is really good at appending and create a new list without change

function syntax is same as JS, however In reason everything is return automatically, let say:

Piping for function: piping is like take in the parameter and from left put in the right side…

this is like someFunction(“string”);

|> is old syntax which takes in the parameter and put it as last argument,

“string” |> someFunction(firstArgument);

and this is like someFunction(firstArgument, “string”);
where new syntax is which will take the parameter and put on left hand side, use |.

“string” |. someFunction(firstArgument);

which is like someFunction(“string”, firstArgument);

piping is really useful when you want to execute multiple level of functions:

example: someFunction(anotherFunction(moreFunction(“string”)))

this is so difficult to read, so do like this:

“string” |. moreFunction |. anotherFunction |. someFunction;

Statement shorthand:
if (x == y) ? true : false;
which is same in reason.

same time you can use if else in reason, however I realised you can’t use just if in reasonml, it has to go with else:

also in javascript if is statement which means you can’t assign to a variable with if statement, but in reason you can:

Pattern match is much:
switch x {
| y => true
| _ => false
}

_ is like all other case …

type variants are like list of variants types, this or that like constructors,

required to use cap for the naming.

can be good for type checking

example :