Pairs and Other Tuples

2019-07-27  本文已影响0人  christ_yang

Pairs

构建:

  1. 语法(syntax):
(e1, e2)
  1. 类型检查(type check):
  1. 求值规则(evaluation rules):

访问:

  1. 语法(syntax):
2-Tuples : 

val e = (e1, e2)
#1 e                         返回e1
#2 e                         返回e2      
  1. 类型检查(type check):
  1. 求值规则(evaluation rules):

Tuples

构建:

  1. 语法(syntax):
(e1, e2, ..., en)
  1. 类型检查(type check):
  1. 求值规则(evaluation rules):

访问:

参考Pairs

实例

简单:
val aPairs = (1, 2)                      (* type: int * int           value: (1, 2) *)
val bPairs = (1+1, 2+4)                  (* type: int * int           value: (2, 6) *)
val cPairs = (true, 2+4)                 (* type: bool * int          value: (true, 6) *)

组合:
val caPairs = (1, (2, 4))                (* type: int * (int * int)              value: (1, (2, 4) *)
val caPairs = (5+6, (2, 3+2))            (* type: int * (int * int)              value: (11, (2, 5) *)
val cPairs = ((true, 1), 2+4)            (* type: ((bool * int) * int)           value: ((true, 1) * 6)

理论上可以嵌套任意层数
上一篇 下一篇

猜你喜欢

热点阅读