Can anybody help me with this function?
getCell :: [[Int]] -> Int -> Int -> Int
Where m i j are the indexes of the lines and the c
Just for fun - one liner
getCell l i j = (((l ++ repeat []) !! i) ++ repeat (-1)) !! j
This should work using the (!!)
operator. First check if index is in the list, then access the element at that index using (!!)
.
getCell m i j = if i >= length m then -1
else let
m0 = m !! i
in if j >= length m0 then -1
else m0 !! j