Programming Language--Section1

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























最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容