Programming Language--Section1
2015-12-20 本文已影响0人
木木瓜
Conditional expression
- Syntax
if e1 then e2 else e3
Where if, then, and else are keywords and e1, e2 and e3 are subexpressions.
-
Type-checking:
First e1 must have type bool, e2 and e3 can have any type (let's call it t), but they must have the same type t. The type of the entire expression is also t. -
Evaluation rules:
Firsgt evaluate e1 to a value call it v1, if it is true, evaluate e2 and that result is the whole expression. else, evaluate e3 and that result is the whole expression's result. -
My own example:
if 8 < 10 then "Hello!" else "So bad."
Then the return of which is
val it = "Hello!" : string