If Else in PureScript
Our first example demonstrates branching with if
and else
in PureScript. This is straightforward and similar to many other programming languages.
To run this program, you would typically compile it with the PureScript compiler and then execute it with Node.js:
Note that in PureScript, you don’t need parentheses around conditions, but you do need to use then
and else
keywords. The do
notation is used for sequencing effects, which is necessary when working with Effect
actions like logging to the console.
PureScript doesn’t have a direct equivalent to Go’s statement preceding conditionals, but we can achieve similar functionality using let
bindings within a do
block.
Also, PureScript doesn’t have a ternary operator, so you’ll need to use full if
-then
-else
expressions even for basic conditions.