美文网首页
Programming Language--Section1

Programming Language--Section1

作者: 木木瓜 | 来源:发表于2015-12-20 09:29 被阅读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
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    相关文章

      网友评论

          本文标题:Programming Language--Section1

          本文链接:https://www.haomeiwen.com/subject/hfqmhttx.html