New to Haskell, and trying to construct an [[(Int, Int)]] where each element is its corresponding grid position, constructed from another board [[a]]. Therefore a square [[a]] of side length 3 would create
[[(0, 0), (1, 0), (2, 0)]
,[(0, 1), (1, 1), (2, 1)]
,[(0, 2), (1, 2), (2, 2)]]
(eventually I'll be iterating over this with a map (map ...) into a function of type [[a]] -> (Int, Int) -> b to create a [[b]], so if I'm missing something massively easier, let me know!)
In Python I might do something like:
[[(x,y) for (x,_) in enumerate(board[y])] for (y,_) in enumerate(board)]
That is to say, I'd use the enumerate builtin to construct (index, element) tuples and throw away the element.
I know in Haskell I can do:
[[(x,y) | x <- [0..length (board!!y)-1]] | y <- [0..length board-1]]
but those sorts of constructions in Python (for foo in range(len(bar))) are a bit of an anti-pattern and heavily discouraged. Is that true in Haskell, as well?
If I were to write the Haskell like I'd write the Python, I'd do:
[[(x,y) | (x,_) <- zip [0..] (board!!y)] | (y,_) <- zip [0..] board]
Is that frowned upon?