
4 Oct
2011
4 Oct
'11
9:23 a.m.
like this? let inits' xs = drop 1 $ inits xs in let getLists n m = inits' take n (repeat m) in f m n =map (\x-> guard $ f x) xs where xs =getLists n m ------------------ Original ------------------ From: "Sebastien Zany"; Date: 2011年10月4日(星期二) 晚上8:27 To: "Haskell Beginners"; Subject: [Haskell-beginners] How to write replicateM with interspersedguards? What would be the idiomatic way to write a function which expands to the following? f n m = do { x1 <- m; guard (f [x1]); x2 <- m; guard (f [x1, x2]); . . . xn <- m; guard (f [x1,x2,...,xn]); } What I'm trying to do is generate a list of lists of length n with some property (checked by f) efficiently.