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.
Suppose stripe(N-1) :: x - [b] - [c]
Then
stripeN :: (a - [b]) - x - [a] - [[c]]
Louis Wasserman wrote:
+1 on Control.Monad.Omega. In point of fact, your diagN function is simply
diagN = runOmega . mapM Omega
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)
Luke Palmer wrote:
I believe you can get what you want using the diagonal function from
Control.Monad.Omega.
product xs ys = [ [ (x,y) | y - ys ] | x - xs ]
diag2 xs ys = diagonal (product xs ys)
I think if you separate taking the cartesian product and flattening
it, like this, you might
+1 on Control.Monad.Omega. In point of fact, your diagN function is simply
diagN = runOmega . mapM Omega
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.