Fsharp: if then (conditional)

By Xah Lee. Date: .

if then else

the true and false branches must agree on type.

printfn "%s" (if 3 = 4 then "yes" else "no" )
// no

elif (else tail chain)

elif is short for if then

let x = 3
let y = 4
printfn "%s" (if x = y then "is equal" elif x < y then "is less than" else "is greater than")
// is less than

if then

it must return a unit type.

(if 3 = 3 then printfn "yes" )
// yes

Reference