so I am having trouble with debugging in OCaml. The problem is that I am writing very simple code, but I keep getting a problem that seems easy to fix – i just don’t know how!
let rec multiplier (int1: int) (int2: int) (int3: int) : int =
let product : int
if int1 >= int2 then(
if int1 >= int3 then product = int1 * int2
else product = int1 * int3
)
else if int2 >= int1 then(
if int1 >= int3 then product = int2 * int1
else product = int2 * int3
)
I keep getting a red ‘x’ and a squigley line under the first “if” with the error : “Unexpected token: if”
Thanks!
Don’t think of
=be an assignment; there basically is no assignment in Ocaml (except:=used for references).Write something like
Remember that the
if…then….else…. construct is an expression; it is more like the ternary?:conditional operator of C than like itsifstatement.Remember that Ocaml don’t have statements, only expressions. (Its
;operator e.ga;bis similar to C comma operatora,bmeaning computea, discard the result, and computebgiving its result for the whole expression)