aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/monads.clj
diff options
context:
space:
mode:
authorKonrad Hinsen <konrad.hinsen@laposte.net>2009-04-23 16:22:23 +0000
committerKonrad Hinsen <konrad.hinsen@laposte.net>2009-04-23 16:22:23 +0000
commitd0eeddf5d8b8bf1a03176b8212bc1610600371da (patch)
treea6fd4d814c1cabbedcfcb8d6b5173f75ce70ddaa /src/clojure/contrib/monads.clj
parent6c99b025c0a2b1afa6736234d3edbf7ea29b1d22 (diff)
monads: fixed m-plus in maybe-t
Diffstat (limited to 'src/clojure/contrib/monads.clj')
-rw-r--r--src/clojure/contrib/monads.clj26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/clojure/contrib/monads.clj b/src/clojure/contrib/monads.clj
index 1995eed5..75a20845 100644
--- a/src/clojure/contrib/monads.clj
+++ b/src/clojure/contrib/monads.clj
@@ -410,28 +410,28 @@
([m nothing] (maybe-t m nothing :m-plus-default))
([m nothing which-m-plus]
(let [which-m-plus (cond (= which-m-plus :m-plus-default)
- (if (= ::undefined (with-monad m m-plus))
- :m-plus-from-maybe
- :m-plus-from-base)
+ (if (= ::undefined (with-monad m m-plus))
+ :m-plus-from-maybe
+ :m-plus-from-base)
(or (= which-m-plus :m-plus-from-base)
(= which-m-plus :m-plus-from-maybe))
- which-m-plus
- :else (throw (java.lang.IllegalArgumentException.
- "undefined m-plus choice")))
+ which-m-plus
+ :else
+ (throw (java.lang.IllegalArgumentException.
+ "undefined m-plus choice")))
combined-m-zero (if (= which-m-plus :m-plus-from-base)
(with-monad m m-zero)
(with-monad m (m-result nothing)))
combined-m-plus (if (= which-m-plus :m-plus-from-base)
(with-monad m m-plus)
(with-monad m
+ ; Note: this works only if the monadic values
+ ; can be equality-tested. It will thus not
+ ; work as expected with the state monad,
+ ; whose monadic values are functions.
(fn [& mvs]
- (m-result (loop [mv (first mvs)]
- (if (nil? mv)
- nothing
- (let [v (m-bind mv identity)]
- (if (identical? v nothing)
- (recur (rest mvs))
- v))))))))]
+ (first
+ (drop-while #(= % combined-m-zero) mvs)))))]
(monad [m-result (with-monad m
m-result)
m-bind (with-monad m