这是我在调用Haskell子字符串函数时为什么会得到"函数中的非详尽模式..."的后续内容?
据我所知,使用-WallGHC可以警告不详尽的模式.我想知道在默认情况下没有使它成为编译时错误的原因是什么,因为它始终可以显式定义部分函数:
f :: [a] -> [b] -> Int
f [] _ = error "undefined for empty array"
f _ [] = error "undefined for empty array"
f (_:xs) (_:ys) = length xs + length ys
Run Code Online (Sandbox Code Playgroud)
问题不是针对GHC的.
是因为......
haskell functional-programming non-exhaustive-patterns partial-functions
我最近安装了Haskell Eclipse插件"EclipseFP".一切都很好,而有一个功能让我很生气呵呵.我无法降低输出的警告级别.Eclipse/It的插件似乎会自动附加"-Wall"标志,这对于类型事物非常敏感.让我们以一个例子来说明这个:
*Main> head [1,2,3]
<interactive>:1:11:
Warning: Defaulting the following constraint(s) to type `Integer'
(Num a0) arising from the literal `3'
In the expression: 3
In the first argument of `head', namely `[1, 2, 3]'
In the expression: head [1, 2, 3]
<interactive>:1:11:
Warning: Defaulting the following constraint(s) to type `Integer'
(Num a0) arising from the literal `3' at <interactive>:1:11
(Show a0) arising from a use of `print' at <interactive>:1:1-12
In the expression: 3
In the first argument …Run Code Online (Sandbox Code Playgroud)