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

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

问题描述

为什么 Clojure 尽管如此强调功能范式,但不使用 Maybe/Option monad 来表示可选值?Option 的使用在 Scala 中非常普遍,Scala 是一种我经常使用的函数式编程语言.

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 不是静态类型的,因此不需要 Haskell 中必需的严格的 this/that/whatever 类型声明(而且,我收集的是 Scala).如果你想返回一个字符串,你就返回一个字符串;如果你改为返回 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.

功能性"并不完全对应于严格的编译时类型".它们是正交的概念,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天全站免登陆