动态 – Clojure Uni-Typed?

栏目: 编程语言 · Clojure · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/23282683/is-clojure-uni-typed
Robert Harper 写了一篇名为 “Dynamic languages are static languages”

的迷人作品.其中写道:

And this is precisely what is wrong with dynamically typed languages: rather than affording the freedom to ignore types, they instead impose the bondage of restricting attention to a single type! Every single value has to be a value of that type, you have no choice! 

has come to mean uni-typed languages .(单一语言).

现在Clojure claims to be a dynamic language

Clojure is a dynamic programming language that targets the Java Virtual Machine (and the CLR, and JavaScript). It is designed to be a general-purpose language, combining the approachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming. Clojure is a compiled language – it compiles directly to JVM bytecode, yet remains completely dynamic . Every feature supported by Clojure is supported at runtime.

“动态”意味着“可以在运行时与之交互”,而不是“没有类型”.

现在静态和动态之间的关键区别似乎是“我可以在编译时遇到类型失败吗?”

如果我写下面的Clojure代码:

(deftype circle-type [radius] )

(deftype square-type [side-length])


(defn def-check-type [new-symbol-type existing-symbol]
 (let [existing-symbol-type (type existing-symbol)]
    (cond 
     (= new-symbol-type existing-symbol-type) 
     (def new-symbol existing-symbol)
     :else (str "types didn't match: " new-symbol-type " : " existing-symbol-type))))

(println (def-check-type circle-type (square-type. 2)));)

然后在Leiningen编译它:

lein uberjar

然后我得到以下内容:

$lein uberjar
Compiling clojure-unittyped.core
types didn't match: class clojure_unittyped.core.circle-type : class clojure_unittyped.core.square-type

在动态语言中,这似乎是编译时的类型失败.

我的问题是:Clojure Uni-Typed?

编辑 – 我知道 core.typed – 这是一项很棒的工作.我问这个问题是分开的.

是的,Clojure是单类型的,但Sam Tobin-Hochstadt argues

的单类型分类在实践中并不是很有用.

单类型理论很少揭示动态类型语言中编程的本质;它主要用于证明类型理论中存在“动态”类型.

Typed Racket 这样的项目被发明,正是为了发现和模拟 程序员 在这些语言中使用的隐式类型信息.通常类型都非常准确,并且表明还有很多东西比满足眼睛要多.

翻译自:https://stackoverflow.com/questions/23282683/is-clojure-uni-typed


以上所述就是小编给大家介绍的《动态 – Clojure Uni-Typed?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

产品经理手册(原书第4版)(白金版)

产品经理手册(原书第4版)(白金版)

[美] 琳达·哥乔斯(Linda Gorchels) / 祝亚雄、冯华丽、金骆彬 / 机械工业出版社 / 2017-8 / 65.00

产品经理的职责起点是新产品开发,贯穿产品生命周期的全过程。本书按上下游产品管理进行组织。 在上游的新产品开发流程中,作者阐述了如何从市场、产品、行业、公司的角度规划企划方案,并获得老板、销售部、运营部的资源支持,推进新产品的项目流程,实现所有目标,制定和实施新产品发布。 下游产品的管理核心在于生命周期的管理,营销更是生命周期管理的重中之重。产品经理如何让产品满足客户需求,让客户获得对产......一起来看看 《产品经理手册(原书第4版)(白金版)》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码

SHA 加密
SHA 加密

SHA 加密工具