我正在尝试在 haskell 中编写一个非常简单的函数来根据输入更改列表中的值,如下所示
update_game :: [Int] -> Int -> Int -> [Int]
update_game (x:xs) row take_amnt | row == 1 = x - take_amnt:xs
| row == 2 = x : head(xs) - take_amnt : tail(xs)
| row == 3 = x : head(xs) : last(xs) - take_amnt`
前两个案例工作正常,但是最后一个案例给我带来了问题,我不确定为什么,我得到的错误是:
最佳答案
:
的第二个参数应该是一个列表,但是 last(xs) - take_amnt
显然只产生一个元素。尝试
row == 3 = x : head(xs) : [last(xs) - take_amnt]
关于list - Haskell List With Guards错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13921676/