[Haskell-cafe] Re: Fair diagonals

2009-11-05 Thread Louis Wasserman
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]]

[Haskell-cafe] Re: Fair diagonals

2009-11-04 Thread Martijn van Steenbergen
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)

[Haskell-cafe] Re: Fair diagonals

2009-11-04 Thread Heinrich Apfelmus
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

[Haskell-cafe] Re: Fair diagonals

2009-11-03 Thread Louis Wasserman
+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.