【问题标题】:What are the similarities and differences between the typing features in Typed Racket and the type-like features in Clojure?Typed Racket 中的打字功能与 Clojure 中的类类型功能有何异同?
【发布时间】:2012-03-22 04:24:17
【问题描述】:

Clojure 有一些用于表示类型的有趣特性,包括但不限于 deftype、defprotocol、reify 和 extend。

Typed Racket 中的打字功能与 Clojure 中的类类型功能有何异同?

【问题讨论】:

    标签: types clojure protocols racket typed-racket


    【解决方案1】:

    deftype 和 defprotocol 在 Clojure 中定义动态行为。在 Racket 中,我们会使用 struct 或 struct-property 来做类似的事情,尽管在 Racket 中没有像 defprotocol 这样的东西。

    编辑: Racket 现在有generics,类似于 Clojure 协议。

    reify 和extend,我认为,对应于在 Racket 中使用make-struct-type,它会动态创建新的结构类型。

    Typed Racket 与所有这些功能的最大区别在于,Typed Racket 在尝试运行之前静态地检查您的程序。您永远不能在 Typed Racket 程序中应用错误的访问器,或者将数字用作函数。您甚至无法运行可能会出现此类错误的程序。

    目前,Clojure 最像 Typed Racket 的特性是它用于性能的注解。

    编辑:现在有 Ambrose Bonnaire-Sergeant 的 Typed Clojure,它的灵感来自 Typed Racket。

    【讨论】:

      猜你喜欢
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-10
      • 1970-01-01
      • 2017-04-01
      • 2017-06-03
      • 2014-11-29
      • 2014-03-08
      相关资源
      最近更新 更多