Why is the use of Maybe/Option not so pervasive in Clojure?

后端 未结 7 2164
长发绾君心
长发绾君心 2020-12-24 01:36

Why does Clojure, despite such an emphasis on functional paradigm, not use the Maybe/ Option monad to represent optional values? The use of O

7条回答
  •  一整个雨季
    2020-12-24 01:38

    Going with @amalloy and comments that Clojure, as a language, doesn't have a need for an optional return value.

    I haven't done much with Scala, but Clojure doesn't need to know the strict details about the return type to be able to work with a value. It's almost as if a Maybe monad was embedded and made a part of normal Clojure evaluation, as many of the operations, if performed on nil, return nil.

    I took a quick look at the Clojure-Contrib library, and they have a monad package which you may want to look at. Another item which really clued me into how one would make use of Monads in Clojure, is Cosmin's tutorial on Monads in Clojure. It was this that help me connect how the functionality that is stated more explicitly in Scala is handled as part of the dynamic Clojure language.

提交回复
热议问题