ts-guide说过:
In addition to the
:
form, almost all binding forms from racket have counterparts which allow the specification of types.
但它没有说明何时使用哪一个。
和 ts-reference说
form:
是遗留的,为了向后兼容。但是在 ts-guide 中,
form:
被用在很多地方。: v t
也是如此优先于 form:
?那么
form
?例如:
; form:
(define: (id [z : Number]) : Number z)
; : v t + form
(: id (-> Number Number))
(define (id z) z)
; form (it seems recent versions of Racket add this?)
(define (id [z : Number]) : Number z)
最佳答案
But it does not say when to use which one.
在大多数情况下,它们是等效的。
我喜欢第二种形式——它可以很容易地再次删除 TR 注释。
关于annotations - 什么时候在 Typed Racket 中使用 `form:`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27795496/