A Lazy Sequence

Error monads revisited

An alternative formulation of error-m and maybe-m that parameterizes the fail rules:

(defn new-error-m
  "Generates a new error-m implementation with the failure behaviour 
   defined by 'failed?'"
  [failed?]
  (monad [m-result identity
          m-bind   (fn [m f] (if (failed? m)
                              m
                              (f m)))]))

;; define our previously hardcoded monads:
(def maybe-m-2 (new-error-m nil?))

(def error-m-2 (new-error-m has-failed?))
25 January 2011