lundi 30 octobre 2017

Multiple if statemens in one Function in SML

i want to write a function in SML which check if the parameters a,b,c are true and then increase the value x everytime by 1.0 - 3.0. For Example:

fun calc(a:bool, b:bool, c:bool, d:int) = 
let
    val x = 0.0
in
    if a=true then x+1.0 else x+0.0
    ;if b=true then x+2.0 else x+0.0
    ;if c=true then x+3.0 else x+0.0
    ;if d<120 then x+4.0 else x+0.0
end

If i run this code with a,b and c true and d<120, then i get the output: val it = 0.0 : real

but i want to get the output of x. (Sorry for my bad english)

Aucun commentaire:

Enregistrer un commentaire