element ::Int->Int->[[Int]]-> Int
element z s m= m!!z!!s
maxIndex :: Int
maxIndex = 6
matrix :: [[Int]] -> Int -> Int -> Int -> Int
matrix a row column maxIndex = if maxIndex < length a then error "Out of range"
else if (row-1<0 || row-1>maxIndex)||(column-1<0 || column-1>maxIndex) then error "Out of range"
else element (row-1) (column-1) a
我在哪里弄错了?我希望我的程序采用我的maxIndex常量,以便用户不必输入maxIndex的值?
答案 0 :(得分:1)
maxIndex
已经是矩阵词法范围内的已定义标识符。就像元素一样,你不需要做任何特别的事情来使用它,所以你可以说:
matrix :: [[Int]] -> Int -> Int -> Int
matrix a row column = ...