I have this SML code. I don’t know why I cannot compile this :
fun score =
let
val sum = 3; (* error at this line : SYNTAX ERROR : inserting LPAREN *)
if sum div 2 > 0
then sum = 0
else sum = 1
(*some other code*)
in
sum (* I want to return sum after some steps of calculation *)
end
There are more issues with your code, than jacobm points out.
You are also missing a function argument. Functions in SML always takes one argument. For example
However this still doesn’t make much sense. since the expressions
sum = 0andsum = 1evaluates to a Boolean.A let-expression is used to make some local declarations which are only visible inside the
in ... endpart. Thus the calculations you wan’t to do with sum, should probably be done inside thein ... endpart, unless you wan’t to express it as a means of a function.One such example is
If we look at the syntax of a let-expression, it probably makes more sense
Since if-then-else is an expression, it can’t be in the “declarations part” by itself.