我很困惑,为什么这个函数的第一个和第三个版本给出这个错误,而第二个定义正常工作。Haskell:函数中的非穷尽模式(简单函数)
-- head and tail
third :: [a] -> a
third [a] = head (tail (tail[a]))
-- Pattern matching
third2 :: [a] -> a
third2 (_:_:x:_) = x
-- List indexing
third3 :: [a] -> a
third3 [a] = [a]!!2
预先感谢
ghc 7.4.1用'-Wall'抱怨了所有三个功能。你使用什么编译器? – 2013-02-15 18:34:20