我真的很新Haskell,我需要返回一个"修改"输入函数的函数.
我想你不能复制和修改原始函数(基于某些条件)所以你必须直接实现自己的行为,然后调用原始函数?
这是我的方法:
switchFirstEgg eggCarton = if eggCarton 1 == 0
then switchedCarton where switchedCarton position = if position == 1 then 2 else eggCarton position
else if eggCarton 1 == 1
then switchedCarton where switchedCarton position = if position == 1 then 0 else eggCarton position
else if eggCarton 1 == 2
then switchedCarton where switchedCarton position = if position == 1 then 1 else eggCarton position
else switchedCarton where switchedCarton position = eggCarton position
Run Code Online (Sandbox Code Playgroud)
我从GHCI得到的错误是
haskell/eggcartons.hs:42:54:输入'在哪里'解析错误
它指向第一个单词之后的第一个单词where …