[Haskell-beginners] lifting to applicative: recomputing an argument each time it is used?

Chaddaï Fouché chaddai.fouche at gmail.com
Sat Sep 8 17:46:18 CEST 2012


On Sat, Sep 8, 2012 at 5:40 PM, Chaddaï Fouché <chaddai.fouche at gmail.com>wrote:

> > listOfN n g = replicateM n g
> >
> > mixIntersperse genSep genWord = do
> >   n <- arbitrary
>

Probably you should rather use

> Positive n <- arbitrary

No reason to waste your time checking empty lists after all...


> >   ws <- listOfN n genWord
> >   ss <- listOfN (n-1) genSep
> >   return $ interlace ws ss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120908/901545d0/attachment.htm>


More information about the Beginners mailing list