[Haskell-beginners] How to write replicateM with interspersed guards?

Sebastien Zany sebastien at chaoticresearch.com
Tue Oct 4 14:29:23 CEST 2011


Just realized I used "f" twice, make the outer one something else.

On Tue, Oct 4, 2011 at 5:27 AM, Sebastien Zany <
sebastien at chaoticresearch.com> wrote:

> 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111004/ab34faa8/attachment.htm>


More information about the Beginners mailing list