344 B
344 B
3.1. The alternative
The if structure
if cond then expr1 else expr2
⚠️
expr1
andexpr2
have to be the same type.cond
is abool
For exemple
# if 1<2 then "higher" else "lower" ;;
-: string = "higher"
Exercise : absolute program
# let abs(x) =
if x>0 then x
else -x ;;;