<div class="gmail_quote">On Sat, Sep 8, 2012 at 4:49 PM, Iain Nicol <span dir="ltr"><<a href="mailto:iain@thenicols.net" target="_blank">iain@thenicols.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I think I'm trying to lift 'Data.List.intersperse' (to applicative or a<br>
monad) in such a way that its (first) argument is recomputed each time<br>
it is used. I'm hoping that there's a reusable, elegant or abstract,<br>
approach for this that I'm unaware of.<br></blockquote></div><br>Instead of using intersperse, just generate two list and interlace them (interlace is easy to write, though not in Data.List :<br><br>> interlace (x:xs) (y:ys) = x : y : interlace xs ys<br>
> interlace xs [] = xs<br>> interlace [] ys = ys<br>> <br>> listOfN n g = replicateM n g<br>> <br>> mixIntersperse genSep genWord = do<br>> n <- arbitrary<br>> ws <- listOfN n genWord<br>
> ss <- listOfN (n-1) genSep<br>> return $ interlace ws ss<br><br>That seems more elegant to me but you'll judge :)<br><br>-- <br>Jedaï<br>