diff options
author | Konrad Hinsen <konrad.hinsen@fastmail.net> | 2009-12-28 15:21:31 +0100 |
---|---|---|
committer | Konrad Hinsen <konrad.hinsen@fastmail.net> | 2009-12-28 15:21:31 +0100 |
commit | 3f893e28ecc0fc2335355aea2cc9324ed5781c81 (patch) | |
tree | 4f724a7067608e4001f68e5207d446f02c4121a2 | |
parent | be33acd87f190d9ec2ad756d8cb31c88abca7e5f (diff) |
finite-distributions: simplified m-bind of dist-m monad
-rw-r--r-- | src/clojure/contrib/probabilities/finite_distributions.clj | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/clojure/contrib/probabilities/finite_distributions.clj b/src/clojure/contrib/probabilities/finite_distributions.clj index 861cdc65..c1dd3a88 100644 --- a/src/clojure/contrib/probabilities/finite_distributions.clj +++ b/src/clojure/contrib/probabilities/finite_distributions.clj @@ -32,11 +32,9 @@ [m-result (fn m-result-dist [v] {v 1}) m-bind (fn m-bind-dist [mv f] - (letfn [(add-prob [dist [x p]] - (assoc dist x (+ (get dist x 0) p)))] - (reduce add-prob {} - (for [[x p] mv [y q] (f x)] - [y (* q p)])))) + (reduce (partial merge-with +) + (for [[x p] mv [y q] (f x)] + [y (* q p)]))) ]) ; Applying the monad transformer maybe-t to the basic dist monad results |