I'm trying to understand recursion so I thought I'd write a simple double for-loop with just raw Haskell (no list comprehensions, no map, etc.).
Given i and j produce the following ..
rTest01 2 5
[[2,5],[2,4],[2,3],[2,2],[2,1],[1,5],[1,4],[1,3],[1,2],[1,1]]
My code works but it doesn't seem beautiful .. I had to add an additional argument to reload the 'j' every time 'i' changes.
Is there a cleaner way to write it?
rTest01 :: Int -> Int -> [[Int]]
rTest01 i j =
[[i,j]] ++ rTest01' j i (j-1)
rTest01' :: Int -> Int -> Int -> [[Int]]
rTest01' origJ i 0 = rTest01' origJ (i-1) origJ
rTest01' _ 0 _ = []
rTest01' origJ i j =
[[i,j]] ++ rTest01' origJ i (j-1)