相关疑难解决方法(0)

在Haskell中,为什么非详尽模式不是编译时错误?

这是我在调用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编译器来执行这种分析?
  • 一个非详尽的模式搜索可以找到一些但不是所有的情况?
  • 部分定义的函数被认为是合法的,并且经常使用不足以强加上面显示的那种构造?如果是这种情况,你能解释一下为什么非详尽的模式是有帮助/合法的吗?

haskell functional-programming non-exhaustive-patterns partial-functions

29
推荐指数
2
解决办法
7817
查看次数

减少Eclipse(类型)警告级别

我最近安装了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)

eclipse haskell

7
推荐指数
2
解决办法
944
查看次数