Struggling with lists of lists in Haskell

前端 未结 2 525
失恋的感觉
失恋的感觉 2021-01-28 15:36

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

2条回答
  •  臣服心动
    2021-01-28 16:24

    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
    

提交回复
热议问题