If Else in Standard ML
Branching with if
and else
in Standard ML is straightforward.
To run this Standard ML program, you would typically use an SML interpreter or compiler. For example, if you’re using SML/NJ (Standard ML of New Jersey), you could save this code in a file named if_else.sml
and run it like this:
Note that in Standard ML, you don’t need parentheses around conditions, but semicolons are used to separate expressions. The then
and else
keywords are required for if-then-else
expressions.
Standard ML doesn’t have a direct equivalent to Go’s ability to declare variables in the condition of an if statement. Instead, we use a let
expression to declare variables before the conditional.
There is no ternary if operator in Standard ML, similar to Go. You’ll need to use a full if-then-else
expression even for basic conditions.