我在Haskell中很新,我有一个非常奇怪的错误:
insertion el [] = [el]
insertion el (x:xs) = | el < x = el:x:xs
| otherwise = x:insertion el xs
这给了我这个错误,在管道后面的caractere的第二行: 输入“|”时解析错误 失败,模块加载:无。
我真的不明白, 你有提示吗? 在此先感谢:)
答案 0 :(得分:5)
当您使用带有函数定义的保护(管道符号)时,不要使用等号的函数名称和参数。它应该写成这样:
insertion el [] = [el]
insertion el (x:xs)
| el < x = el:x:xs
| otherwise = x:insertion el xs
第一个后卫不需要在下一行,但这往往是一般风格。