algo.monads

maybe-m breaks the monad laws.

Details

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

Description

One of the monad laws is that (m-bind (m-result v) f) should be the same as (f v). However, this is not the case in maybe-m:

user=> (with-monad maybe-m (m-bind (m-result nil) nil?))
nil

user=> (nil? nil)
true

The crux of the problem is that in algo.monad's maybe-m, there is no way to wrap a nil in a Just-like container.

Activity

Hide
Seth J. Gold added a comment -

Just realized that that demonstration doesn't actually work, because the function passed to m-bind is supposed to return a monadic value. Here's a better one:

user=> (with-monad maybe-m (m-bind (m-result nil) (comp m-result nil?)))
nil
user=> (with-monad maybe-m ((comp m-result nil?) nil))
true

Show
Seth J. Gold added a comment - Just realized that that demonstration doesn't actually work, because the function passed to m-bind is supposed to return a monadic value. Here's a better one: user=> (with-monad maybe-m (m-bind (m-result nil) (comp m-result nil?))) nil user=> (with-monad maybe-m ((comp m-result nil?) nil)) true

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated: