我有这个代码:
type Matrice = [[String]]
matr =[[" - "," 0 "," - "],[" - "," - "," - "],[" - "," - "," - "]]
changeValue :: Matrice ->Int->Int->Matrice
changeValue mat x y = [
if ((mat !! x) !! y) /= " - "
then mat
else do (replaceNth y " P " xs)
| xs <- (mat !! x)
]
replaceNth :: 函数将位置值 ' - ' 替换为 (' P ')
replaceNth :: Int -> String -> [String] -> [String]
replaceNth n newVal (x:xs)
| n == 0 = newVal:xs
| otherwise = x:replaceNth (n-1) newVal xs
我想将矩阵中的每个案例都更改为 ' - ' 为 ' P '
但它不工作,我总是这个错误:
couldn't match type [char] with char