为什么在Clojure中Maybe / Option的使用不那么普遍? [英] Why is the use of Maybe/Option not so pervasive in Clojure?

查看:89
本文介绍了为什么在Clojure中Maybe / Option的使用不那么普遍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Clojure尽管强调了功能范例,却不使用 Maybe / Option 可选值?在我使用的函数式编程语言Scala中, Option 的使用非常普遍。

Why does Clojure, despite such an emphasis on functional paradigm, not use the Maybe/ Option monad to represent optional values? The use of Option is quite pervasive in Scala, a functional programming language I use regularly.

推荐答案

Clojure不是静态类型,所以不需要严格的this / that /任何类型的声明在haskell (和,我收集,斯卡拉)。如果你想返回一个字符串,你返回一个字符串;如果你返回nil,那也没问题。

Clojure is not statically typed, so doesn't need the strict this/that/whatever type declarations that are necessary in haskell (and, I gather, Scala). If you want to return a string, you return a string; if you return nil instead, that's okay too.

Functional不完全对应于严格的编译时打字。它们是正交概念,Clojure选择动态类型。事实上,在一段时间之后,我无法想象如何实现许多高级函数,如 map ,仍然保留静态类型。现在我有一个(很少)Haskell的经验,我可以看到,这是可能的,而且的确经常相当优雅。我怀疑,如果你玩Clojure一段时间,你会有相反的经验:你会意识到类型声明不是必要的给你的那种力量,你习惯了在功能语言中。

"Functional" does not correspond exactly to "strict compile-time typing". They are orthogonal concepts, and Clojure chooses dynamic typing. In fact, for quite some time I couldn't imagine how you could implement many of the higher-order functions like map and still preserve static typing. Now that I have a little (very little) experience with Haskell, I can see that it's possible, and indeed often quite elegant. I suspect that if you play with Clojure for a while, you will have the opposite experience: you'll realize the type declarations aren't necessary to give you the kind of power you're used to having in a functional language.

这篇关于为什么在Clojure中Maybe / Option的使用不那么普遍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆