7

I recently installed the Haskell Eclipse-plugin "EclipseFP". Everything works pretty well while there's one feature which makes me very angry hehe. I cannot reduce the warning level of the output. Eclipse/It's plugin seems to auto-append the "-Wall" flag, which is very very sensitive against type-things. Let's show this on an example:

*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> 

Yep, that is REALLY annoying. It's caused by "intrinsic" functions as well as on custom ones. Another one:

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> 
Kara
  • 6,115
  • 16
  • 50
  • 57
poitroae
  • 21,129
  • 10
  • 63
  • 81

4 Answers4

6

I don't know about Eclipse, but you can off warnings in your .ghci file. Put

:set -Wall           -- unnecessary if Eclipse already turns it on
:set -fno-warn-type-defaults
:set -fno-warn-unused-do-bind

and whatever else you don't want to warned about by default into your ~/.ghci and reduce the warnings to the important ones. If you want to load some modules by default, you can also add import Control.Applicative (or whichever).

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
  • 1
    Thanks, that did the job. Note that on windows, the path would be C:\Users\\AppData\Roaming\ghc\ghci.conf - Create the file and copy the above if the file does not exist, yet. – poitroae Jan 26 '12 at 19:46
5

in .cabal file write: ghc-options: -Wall -fno-warn-type-defaults -fno-warn-unused-do-bind

Gerold Meisinger
  • 4,500
  • 5
  • 26
  • 33
2

There is a way to put those commands suggested by Daniel Fischer right in EclipseFP.

Open "Run Configurations...", select yours, switch to "Automation" tab, type in a command in the text edit. Unfortunately, it's a one-line edit entry and GHCI doesn't support several commands in one line.

However, you can type multi-line text somewhere and paste it in this text edit so that it will look like :set -fno-warn-type-defaults[000A]:set -fno-warn-unused-do-bind.

There is also a special multi-line text edit named "Arguments" but it doesn't solve the problem since these arguments are inserted before that -Wall, that's why they don't make sense.

Community
  • 1
  • 1
kirikaza
  • 2,659
  • 2
  • 15
  • 14
  • 1
    It is Okay to put two options on one set command like :set -fno-warn-type-defaults -fno-warn-unused-do-bind – The_Ghost Oct 25 '12 at 16:27
1

Another approach, instead of adding arguments to switch off this behaviour, is to prevent it being switched on in the first place.

Inside the Eclipse haskell project, there is a file called eclispeProjectName.cabal. This is where the -Wall ghci argument is defined. Comment out that line.

For example: in an eclipse haskell project called haskelltest, there is a file called haskelltest.cabal at the top level of the project. Set its contents like below - see the last line where I've commented out the ghc-options setting:

name:           haskelltest
version:        0.1
cabal-version:  >=1.2
build-type:     Simple
author:         marty

executable haskelltest
  hs-source-dirs:  src
  main-is:         Main.hs
  build-depends:   base >= 4
--  ghc-options:     -Wall
Martin Devlin
  • 71
  • 1
  • 1
  • BTW Apparently turning off the -Wall setting is considered bad practise. See [link](http://stackoverflow.com/questions/4174629/impact-on-style-of-ghc-wall) so lambdor's approach is probably better. – Martin Devlin Aug 09 '13 at 10:51