Map and Reduce Monad for Clojure… What about a Juxt Monad?

后端 未结 3 1879
感动是毒
感动是毒 2021-02-03 13:58

Whilst learning Clojure, I\'ve spent ages trying to make sense of monads - what they are and how we can use them.... with not too much success. However, I found an excellent \'M

3条回答
  •  逝去的感伤
    2021-02-03 14:46

    Your examples are not monads. A monad represents composable computational steps. In the trivial identity monad, the computational step is just an expression evaluation.

    In the maybe monad, a step is an expression that may succeed or fail.

    In the sequence monad, a step is an expression that produces a variable number of results (the elements of the sequence).

    In the writer monad, a computational step is a combination of expression evaluation and log output. In the state monad, a computational step involves accessing and/or modifying a piece of mutable state.

    In all these cases, the monad plumbery takes care of correctly combining steps. The m-result function packages a "plain" value to fit into the monadic computation scheme, and the m-bind function feeds the result of one computational step into the next computational step.

    In (map + a b), there are no computational steps to be combined. There is no notion of order. It's just nested expression evaluation. Same for reduce.

提交回复
热议问题