Context
I’m currently reading about Clojure’s implementation of monads: org.clojure/algo.monads
Intuitively, reduce looks like a state-m applied to a map. Basically, there’s the “state” which is the value so far.
Now, I can’t make this work in the “standard way because:”
(domonad state-m
[ ... I can only stuff a constant number of things here ...
... but I need to stuff here a list whose size is only known at run time ... ]
..)
Question
Is there some way to implement reduce as a monad using state-m?
I know I would never use this in practice, this is purely for enlightenment + better understanding how things fit together.
Thanks!
I don’t think what you are asking for is possible using
domandmacro (without runtime code generation and evaling it). One option would be to usem-bindandm-resultfunctions of the state monad directly to get the desired behavior.