为了交换列表的前两个元素,我编写了以下代码:
swap_first_two_elements :: [a]->[a]
swap_first_two_elements list=case list of
x:y:_ -> y:x:_
[x] -> Nothing
[]-> Nothing
但是,终端显示如下所示的错误:
[1 of 1] Compiling Main ( test.hs, interpreted )
test.hs:3:16: Pattern syntax in expression context: _
Failed, modules loaded: none.
Prelude>
谁喜欢告诉我它有什么问题?
顺便说一句,我还尝试将最后两行合并为:
[x] || [] ->Nothing
怎么错了?终端显示:
test.hs:4:3: Parse error in pattern: [x] || []
Failed, modules loaded: none.
谁喜欢告诉我它有什么问题?谢谢XD