I'm trying to convert a list to an array (list of lists) from a function that receives an Int (i) that is a counter that always starts at 0, another Int (n) that is the length of each row and the list that I have to convert to matrix.
createMatrix :: (Int, Int, [Int]) -> [[Int]]
createMatrix (i, n, ([])) = []
createMatrix (i, n, (x:y)) = if (i < n) then [x] : createMatrix (i+1, n, (y))
else [] ++ createMatrix (0, n, (x:y))
This gives me as output:
[[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18]]
when it should be something like:
[[1,2,3,4,5,6],[7,8,9,10,11,12],[13,14,15,16,17,18]]
in case n is 6
Does anyone have an idea that I may be failing? I tried several things and found no solution.
Thanks