(with-monad dist-m
(defn- select-n [n xs]
(letfn [(select-1 [[s xs]]
(uniform (for [i (range (count xs))]
(let [[nth rest] (nth-and-rest i xs)]
(list (cons nth s) rest)))))]
((m-chain (replicate n select-1)) (list '() xs))))
(defn select [n xs]
"Return the distribution for all possible ordered selections of n elements
out of xs."
((m-lift 1 first) (select-n n xs)))
)
Comments top
No comments for select. Log in to add a comment.