Clojure 序列类型
正确的序列类型是什么?我有这段代码:
(defrecord MethodInfo [^clojure.lang.ISeq preconds ^clojure.lang.ISeq postconds])
但它似乎没有正确执行类型要求,因为我可以编写 (new MethodInfo 1 2)
。
What's the correct type of a sequence? I have this code:
(defrecord MethodInfo [^clojure.lang.ISeq preconds ^clojure.lang.ISeq postconds])
But it doesn't seem to correctly enforce the type requirements, since I can write (new MethodInfo 1 2)
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的理解是,Clojure 的 类型提示 只是出于性能原因,通过回避反射来改进方法查找;这是它们的唯一目的,而不是在动态语言中强制执行静态类型。
请参阅类似问题的答案。
编辑:
有说法称能够强制执行原语在 Clojure 1.3 中,某些情况下会返回类型,但这显然是不断变化的,并且仍然不适用于序列类型。
My understanding is that Clojure's Type Hints are only there for performance reasons, to improve method lookup by side-stepping reflection; That is their only purpose, and not to enforce static types in a dynamic language.
Please see this answer to a similar question.
Edit:
There is talk of being able to enforce primitive return types in some cases in Clojure 1.3, but this is clearly something that's in flux, and still wouldn't apply to sequence types.