I figured out an inductive approach as follows, which lets you derive stripeN from stripe(N-1). This could be TemplateHaskell'd if you have a bound on N; I'm still trying to figure out a type-magical alternative.<br>
<br>Suppose stripe(N-1) :: x -> [b] -> [c]<br><br>Then<br><br>stripeN :: (a -> [b]) -> x -> [a] -> [[c]]<br>stripeN f x [] = []<br>stripeN f x (a:as) = case stripe(N-1) x (f a) of<br><div style="margin-left: 40px;">
[] -> stripeN f x as<br>(b:bs) -> [b]:zipCons bs (stripeN f x as)<br><br></div>and then diagN is obtained by applying concat an appropriate number of times. It's fair. The real-question is how to type-magically work it for arbitrarily many coordinates...<br>
<br><br clear="all">Louis Wasserman<br><a href="mailto:wasserman.louis@gmail.com">wasserman.louis@gmail.com</a><br><a href="http://profiles.google.com/wasserman.louis">http://profiles.google.com/wasserman.louis</a><br>
<br><br><div class="gmail_quote">On Wed, Nov 4, 2009 at 4:38 AM, Martijn van Steenbergen <span dir="ltr"><<a href="mailto:martijn@van.steenbergen.nl">martijn@van.steenbergen.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Louis Wasserman wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
+1 on Control.Monad.Omega. In point of fact, your diagN function is simply<br>
<br>
diagN = runOmega . mapM Omega<br>
<br>
You'll find it an interesting exercise to grok the source of Control.Monad.Omega, obviously, but essentially, you're replacing concatMap with a fair (diagonal) traversal order version.<br>
</blockquote>
<br></div><div><div></div><div class="h5">
Thanks for the replies!<br>
<br>
I've looked at Omega but it's not fair enough. The sums of the indices are not non-decreasing:<br>
<br>
map sum $ runOmega . mapM each $ [[1..], [1..], [1..]]<br>
[3,4,4,4,5,5,5,5,6,6,5,6,6,7,7,5,6,7,7,8,8,6,6,7,8,8,9,9,6,7,...<br>
<br>
Is there another way to use Omega that meets this (very important) criterion or is Omega not the right tool here?<br>
<br>
Thanks,<br>
<br>
Martijn.<br>
</div></div></blockquote></div><br>