[ALGOM-10] :when clause in domonad relies on optional m-zero monad operation Created: 30/May/13 Updated: 05/Feb/14 Resolved: 05/Feb/14
|Reporter:||Glenn Vanderburg||Assignee:||Konrad Hinsen|
In add-monad-step, the :when clause is implemented by this line:
which makes sense, except that m-zero is an optional operation for monads.
I don't know that it's possible to make this work reasonably for all monads,
|Comment by Glenn Vanderburg [ 03/Jun/13 8:23 AM ]|
After more thinking, I think the best behavior would be to evaluate to m-zero if it's defined, and (m-result nil) otherwise. The behavior of :when is too useful with the state monad, and too cumbersome to duplicate with :if :then :else, to simply document the issue. The standard Clojure when macro evaluates to nil if the condition is false.
|Comment by Konrad Hinsen [ 05/Feb/14 9:50 AM ]|
The docstring for domonad clearly says that :when requires a definition of m-zero. I am not in favor of removing this rule, which has a clear role in the monad framework. "No value" is not in general the same as "a value of nil", so substituting (m-result nil) as a default for m-zero doesn't look like a good idea.
A better error message would indeed be desirable but I see no obvious implementation, because of the possibility of generic domonad forms for which the monad is specified later. As a workaround, I have replaced the ::undefined value by more descriptive symbols that convey a useful message to the reader: