-
类型签名:(: name : type) (:print-type expression)
- 匿名函数的标识和struct的标识与一般的不同
(lambda ([param-1 : ty-1] ... [param-n : ty-n]) expr)
-
基本类型:
- Natural
- Integer
- Exact-Rational
- Real
- Number
- Boolean
- String
- Symbol
-
作用:减少错误、性能优化、利于阅读
-
词法作用域:静态作用域
-
union type: (: U T_1 T_2 ... T_k)
-
single type:枚举类型
(: R : 'red) (define R 'red) This kind of type is called a singleton type, since it is a type that has exactly one value. By combining multiple singleton types in a union, we can describe enumeration types. For example, our color type is the union of 'red, 'green, and 'blue. Two other useful singleton types are #t and #f (as one might guess, Boolean is the union of #t and #f). (: color-to-string : (U 'red 'green 'blue) -> String) ;; convert a color to a string (define (color-to-string c) (cond [(symbol=? c 'red) "red"] [(symbol=? c 'blue) "blue"] [else "green"]))
-
Type definitions:
;; A color is one of 'red, 'blue, or 'green. we can give an explicit definition using the define-type construct (define-type Color (U 'red 'blue 'green))
-
Subtyping
使用U
-
Pattern-matching gotchas:
-
递归类型
-
多态函数和多态类型
(All (A B) (Two-Things A B) -> (Two-Things B A)) is called universal quantification and it means "for all types A and B a function from (Two-Things A B) to (Two-Things B A)". If we apply swap to a value of type (Two-Things Integer Boolean)
-
高阶函数
-
Listof和Vectorof
-
命令式:
(void):
-
ctrl + i 格式化代码
-
optional,要么空,要么有值。maybe,maybe monad
-
将现存类型命名成新类型
-
match*:模式匹配多个值
-
match:== 相等扩展
https://blog.csdn.net/yeswenqian/article/details/22291675
boxOf
cast