我的功能:故障基本情况哈斯克尔
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