algo.monads

:when clause in domonad relies on optional m-zero monad operation

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

In add-monad-step, the :when clause is implemented by this line:

(identical? bform :when)  `(if ~expr ~mexpr ~'m-zero)

which makes sense, except that m-zero is an optional operation for monads.
If :when is used with a monad that does not provide an m-zero operation,
the result (in cases where the condition evaluates to false) is an incorrect monadic value,
and strange, difficult-to-understand errors result.

I don't know that it's possible to make this work reasonably for all monads,
but at the very least the limitation should be documented, and ideally the use of :when
with a monad that does not define m-zero should issue a warning with a recommendation that
{:if :then :else} should be used instead.d

Activity

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: