我最近安装了 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 of `head', namely `[1, 2, 3]'
In the expression: head [1, 2, 3]
1
*Main>
是的,这真的很烦人。它是由“内在”功能以及自定义功能引起的。
另一个:
factorial :: (Integral a) => a -> a
factorial 1 = 1
factorial n = n * factorial (n-1)
*Main> factorial 3
<interactive>:1:1:
Warning: Defaulting the following constraint(s) to type `Integer'
(Integral a0) arising from a use of `factorial'
at <interactive>:1:1-9
(Num a0) arising from the literal `3' at <interactive>:1:11
In the expression: factorial 3
In an equation for `it': it = factorial 3
<interactive>:1:1:
Warning: Defaulting the following constraint(s) to type `Integer'
(Integral a0) arising from a use of `factorial'
at <interactive>:1:1-9
(Num a0) arising from the literal `3' at <interactive>:1:11
(Show a0) arising from a use of `print' at <interactive>:1:1-11
In the expression: factorial 3
In an equation for `it': it = factorial 3
6
*Main>
最佳答案
我不了解 Eclipse,但您可以在 .ghci
中关闭警告。文件。放
:set -Wall -- unnecessary if Eclipse already turns it on
:set -fno-warn-type-defaults
:set -fno-warn-unused-do-bind
以及默认情况下您不想警告的任何其他内容到您的
~/.ghci
并减少对重要的警告。如果想默认加载一些模块,也可以加import Control.Applicative
(或任何一个)。
关于eclipse - 降低 Eclipse(类型)警告级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9022431/