Firstly, this doesn't make any sense. An if-then-else
must have all three parts: you can not omit the else
, which your trailing if-then
clearly does.
Secondly, multiple statements (separated by ;
) are only useful when there are side-effects, which there are not. You may change your code to
fun function (a, b) =
( if size a < 2 then a ^ " " else
if size a < 3 then a ^ " " else
a
; if size b < 2 then b ^ " " else
if size b < 3 then b ^ " " else
b
)
but the result of the first statement will be discarded, and is completely useless.
Perhaps you want something more like
fun padLeft (n, a) =
if size a < n
then a ^ CharVector.tabulate(n - size a, fn _ => #" ")
else a
fun function1 (a, b) = (padLeft (3, a), padLeft (3, b))
fun function2 (a, b) = (print (padLeft (3, a)); print (padLeft (3, b)))
where function1
returns a pair using both inputs, and function2
returns unit
but has a visible side-effect using both inputs.
ephemient
2009-12-14 18:54:14