型別

簡單型別

數字

  • int:整數,初期可用 64 位元帶符號整數處理。

  • dou:雙精度浮點數

字串

  • str:字串

暫不支援 char

布林

  • bool:布林值。#t:真值,#f:假值。

複雜型別

自訂型別

可以自訂 product type 或 sum type。為求簡化,不支援型別當參數。

(Type TYPE-NAME (Type-constronctor x1 x2 ...))
(Type TYPE-NAME (U (Type-const1 x1 x2 ...)(Type-const2 x1 x2 ...)...))
(Type TYPE-NAME (Type-constronctor))
(Type TYPE-NAME (U (Type-const1)(Type-const2)...))

U 是 union 的意思,指 Sum Type。

例如:

(Type IntPair (IntPair Int Int))

如果可以模式匹配,就變這樣:

(\ ((IntPair x))
  (match (x)
    ((IntPair 7 9) 9)
    ((IntPair 8 a) a)
    ((IntPair x y) (+ x y))))

Sum Type 的用法:

(Type OrigColor (U (Red)(Green)(Blue))) ; 三原色

如果可以模式匹配,就變這樣:

(orig-color-to-str ((OrigColor x))
  (match (x)
    ((Red) "Red")
    ((Green) "Green")
    ((Blue) "Blue")))