我的功能:故障基本情況哈斯克爾
type Block = [Maybe Int]
checkBlock' :: Block -> Block
checkBlock' (r:rs)
| r == [] = []
| isJust r == True = r:checkBlock' rs
| isNothing r == True = checkBlock' rs
checkBlock :: Block -> Block
checkBlock (r:rs)
| r == [] = []
| isNothing r == True = r:checkBlock rs
| isJust r == True = checkBlock rs
我想第1功能檢查就INTS和空話的列表,只有返回剛纔值。而第二個函數只返回Nothings。
他們蒐集精而不basecase其中r == [] = []
,但它我得到的錯誤:
Sudoku.hs:104:12:
Couldn't match expected type `Maybe Int' with actual type `[t0]'
In the second argument of `(==)', namely `[]'
In the expression: r == []
In a stmt of a pattern guard for
an equation for checkBlock':
r == []
Failed, modules loaded: none.
我可以把那裏,而不是[],使這個編譯?我沒有想法。
神感謝,emberrasing! – Rewbert 2014-10-07 15:13:13
@Rewbert另請注意,'x == True'與'x'完全相同。你應該只有'| isNothing r = r:checkBlock rs',對於下一行也是類似的。 – bheklilr 2014-10-07 15:14:09
'checkBlock = filter isNothing' – 2014-10-07 15:18:59