2012-01-26 3 views
7

최근에 Haskell Eclipse 플러그인 "EclipseFP"를 설치했습니다. 나를 화나게하는 기능이 하나있는 반면 모든 기능은 꽤 잘 작동합니다. hehe. 출력의 경고 수준을 줄일 수 없습니다. 이클립스/플러그인은 "-Wall"플래그를 자동으로 추가하는 것으로 보이는데 이는 형식에 매우 민감합니다. 의이 예에서이 보여 드리죠 :Eclipse (유형) 경고 수준 줄이기

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

경고가 처음에 나타나지 않으므로 실제로이 코드를 작성 하시겠습니까? –

답변

6

이클립스에 대해 잘 모르지만, 당신은 당신의 .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 (또는 둘 중 하나)을 추가 할 수도 있습니다.

+1

고마워요, 그 일을했습니다. Windows에서 경로는 C : \ Users \ \ AppData \ Roaming \ ghc \ ghci.conf입니다. 파일을 생성하고 파일이 존재하지 않으면 위의 파일을 복사하십시오. – poitroae

2

EclipseFP에서 해당 명령 suggested by Daniel Fischer을 올바르게 삽입하는 방법이 있습니다.

열기 "실행 구성 ...은"선택 당신은 텍스트 편집의 명령에 "자동화"탭, 유형을 전환 할 수 있습니다. 불행히도 한 줄 편집 항목이고 GHCI는 한 줄에 여러 명령을 지원하지 않습니다.

그러나 어딘가에 여러 줄로 된 텍스트를 입력하고이 텍스트 편집에 붙여 넣으면 :set -fno-warn-type-defaults[000A]:set -fno-warn-unused-do-bind처럼 보일 수 있습니다. 그들이 이해가되지 않는 이유

있다 "인수"라는 이름의 특별한 멀티 라인 텍스트 편집도 있지만 이러한 인수가 -Wall 앞에 삽입되기 때문에 문제가 해결되지 않는, 즉이다. .cabal 파일 쓰기에

+1

두 개의 옵션을 하나의 set 명령에 두는 것이 좋습니다 : set -fno-warn-type-defaults -fno-warn-unused-do-bind –

5

: 대신이 동작을 전환하는 인수를 추가 ghc-options: -Wall -fno-warn-type-defaults -fno-warn-unused-do-bind

1

또 다른 방법은, 그것은 처음에 스위치되지 않도록하는 것입니다.

Eclipse haskell 프로젝트 내에는 eclispeProjectName .cabal이라는 파일이 있습니다. 이것은 -Wall ghci 인수가 정의 된 곳입니다. 그 줄을 주석 처리하십시오.

예 : haskelltest라는 이클립스 haskell 프로젝트에는 프로젝트 최상위 레벨에 haskelltest.cabal이라는 파일이 있습니다. 그 내용을 아래와 같이 설정하십시오. ghc-options 설정을 주석 처리 한 마지막 행을 참조하십시오.

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 
+0

BTW 분명히 -Wall 설정을 끄는 것은 나쁜 습관으로 간주됩니다. [링크] (http : // stackoverflow.com/questions/4174629/impact-on-style-of-ghc-wall) 그래서 lambdor의 접근 방식이 아마도 더 좋습니다. –

관련 문제