(use 'clojure.contrib.monads)
; Clojure 1.3: (use 'clojure.algo.monads)
;; We want to combine failing computations and nondeterminism
;; The sequence monad is not sufficient
user=> (domonad sequence-m [x [2 nil 3] y [2 3]] (* x y))
NullPointerException clojure.lang.Numbers.ops (Numbers.java:942)
;; Create a combined monad by applying the maybe-t monad transformer
user=> (def maybe-seq-m (maybe-t sequence-m))
#'user/maybe-seq-m
;; The combined monad can handle failing computations
user=> (domonad maybe-seq-m [x [2 nil 3] y [2 3]] (* x y))
(4 6 nil 6 9)
(use 'clojure.contrib.monads)
; Clojure 1.3: (use 'clojure.algo.monads)
;; We want to combine failing computations and nondeterminism
;; The sequence monad is not sufficient
user=> (domonad sequence-m [x [2 nil 3] y [2 3]] (* x y))
NullPointerException clojure.lang.Numbers.ops (Numbers.java:942)
;; Create a combined monad by applying the maybe-t monad transformer
user=> (def maybe-seq-m (maybe-t sequence-m))
#'user/maybe-seq-m
;; The combined monad can handle failing computations
user=> (domonad maybe-seq-m [x [2 nil 3] y [2 3]] (* x y))
(4 6 nil 6 9)