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

后端 未结 7 2163
长发绾君心
长发绾君心 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 02:01

    Maybe/Option is a type. It has nothing to do with functional programming. Yes, some languages (Scala, haskell, ocaml) besides being functional also provide a very powerful type system. People even say about haskell that it is a programming WITH TYPES.

    Others (clojure, lisp) do not provide much in terms of types even though they are fully capable functional languages. Their emphasis is different, and Maybe/Option type does not fit in. It simply does not give you much in dynamic language. For example many clojure functions operating on sequences (lists, vectors, maps) will perfectly accept null (nil) and treat it as empty structure.

    (count nil) will give you 0. Just like (count [])

    Clojure cannot be called a "programming with types" and thus Maybe type does not make much sense in it.

    0 讨论(0)
提交回复
热议问题