我在haskell制作mortal-fibonacci兔子程序时遇到问题。 凡人这个词意味着兔子出生后3个月就死了
这是我的haskell代码
mortalRabbits xs 0 = xs
mortalRabbits xs n = mortalRabbits xs' (n-1)
where xs' = updateRabbits xs
updateRabbits (x:xs) =
case x of
0 = [1] ++ updateRabbits xs
1 = [2, 0] ++ updateRabbits xs
2 = [3, 0] ++ updateRabbits xs
3 = [] ++ updateRabbits xs
和ghci保持打印" num2.hs:3:1:输入解析错误'其中'"'并拒绝加载我的代码。
所以我删除了行'其中xs' = updateRabbits xs' 并将第2行改为' mortalRabbits xs n = mortalRabbits(updateRabbits)(n-1)'。
但这一次,ghci保持打印" num2.hs:7:19:输入解析错误' ='。
我认为这两个错误是相同的情况。 我是哈斯克尔地区的新生婴儿。那么你能告诉我它里面发生了什么吗? btw srry为我可怜的Eng。
答案 0 :(得分:1)
供您参考,以下是代码的语法修复版本:
mortalRabbits xs 0 = xs
mortalRabbits xs n = mortalRabbits xs' (n-1)
where xs' = updateRabbits xs
updateRabbits (x:xs) =
case x of
0 -> [1] ++ updateRabbits xs
1 -> [2, 0] ++ updateRabbits xs
2 -> [3, 0] ++ updateRabbits xs
3 -> [] ++ updateRabbits xs