diff categorical/monad.clj @ 2:b4de894a1e2e

initial import
author Robert McIntyre <rlm@mit.edu>
date Fri, 28 Oct 2011 00:03:05 -0700
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/categorical/monad.clj	Fri Oct 28 00:03:05 2011 -0700
     1.3 @@ -0,0 +1,14 @@
     1.4 +
     1.5 +(ns categorical.monad)
     1.6 +(use 'clojure.contrib.monads)
     1.7 +
     1.8 +(in-ns 'categorical.monad)
     1.9 +
    1.10 +;; To implement nondeterministic programs, we'll use a lazy seq to represent a value which may be any one of the members of seq.
    1.11 +
    1.12 +(defmonad amb
    1.13 +  [
    1.14 +   m-result (fn[& vals] (cons 'amb vals))
    1.15 +   m-bind (fn[amb-seq f] (cons 'amb (map f (rest amb-seq))))
    1.16 +   ]
    1.17 +)