NEXT ·  UP ·  PREVIOUS ·  CONTENTS ·  INDEX

Sequential composition

In imperative programming it is essential to have a method of controlling the order in which the evaluation of the components of a compound expression takes place. We wish to be able to build a sequence of expressions into a single compound expression. Given expressions e1, e2 and e3 we could force them to be evaluated in the correct order by using let .. in .. end as shown below. We are not interested in the results of the expressions, we simply throw them away by using the wild card as the pattern in the value binding.

     let
         val _ = e1
         val _ = e2
     in
         e3
     end

This seems rather cumbersome. Fortunately Standard ML provides a neater way to control the order of evaluation of expressions. The composition operator in Standard ML is a semicolon and parentheses may be used to build a single expression from a sequence of expressions. There is no requirement for all of the subexpressions to return the unit value as their result or to have the same type. The expression (n := 5; true) evaluates to true. The expression (true; n := 5) evaluates to ().

NEXT ·  UP ·  PREVIOUS ·  CONTENTS ·  INDEX