<div style="font-family:Verdana;font-size:14px;color:#000;"><div>like this?</div><div>let inits' xs = drop 1 $ inits xs in</div><div>let getLists n m = inits' take n (repeat m) in</div><div>f m n =map (\x-&gt; guard $ f x) xs&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where xs =getLists n m&nbsp;</div>
<div style="font:Verdana normal 14px;color:#000;padding:8px 0px;"><div>&nbsp;</div><div>&nbsp;</div><div style="FONT-SIZE: 12px;FONT-FAMILY: Arial Narrow;padding:2px 0 2px 0;">------------------&nbsp;Original&nbsp;------------------</div><div style="FONT-SIZE: 12px;background:#efefef;padding:8px;"><div><b>From:</b> "Sebastien Zany"<sebastien@chaoticresearch.com>; </div><div><b>Date:</b> 2011年10月4日(星期二) 晚上8:27</div><div><b>To:</b> "Haskell Beginners"<beginners@haskell.org>; </div><div><b>Subject:</b> [Haskell-beginners] How to write replicateM with interspersedguards?</div></div><div>&nbsp;</div>What would be the idiomatic way to write a function which expands to the following?<div><br></div><div>f n m = do {</div><div>x1 &lt;- m;</div><div>guard (f [x1]);</div><div>x2 &lt;- m;</div><div>guard (f [x1, x2]);</div><div>


.</div><div>.</div><div>.</div><div>xn &lt;- m;</div><div>guard (f [x1,x2,...,xn]);</div><div>}</div><div><br></div><div>What I'm trying to do is generate a list of lists of length n with some property (checked by f) efficiently.</div>



  <!-- --><style></style></div></div>