경고

2011-05-05 5 views
7

나는경고

$ GHC --make -O2 -Wall -fforce-recomp

[1 일의] 컴파일을 컴파일하려고 다음과 같은 오류가 홈페이지 ( isPrimeSmart.hs, isPrimeSmart.o) SpecConstr 기능 '$의 WA {V s2we} [뚜껑] 두 호출 패턴을 가지고 있지만, 제한 한 사용 -fspec-은 constr 카운트이다 = n을 설정하도록 바인딩 특수화를 보려면 -dppr-debug를 사용하십시오. isPrimeSmart를 연결하십시오. 은 ...

내 코드는 다음과 같습니다

{-# OPTIONS_GHC -O2 -optc-O2 #-} 

import qualified Data.ByteString.Lazy.Char8 as StrL -- StrL is STRing Library 
import Data.List 

-- read in a file. First line tells how many cases. Each case is on a separate 
-- line with the lower an upper bounds separated by a space. Print all primes 
-- between the lower and upper bound. Separate results for each case with 
-- a blank line. 
main :: IO() 
main = do 
    let factors = takeWhile (<= (ceiling $ sqrt (1000000000::Double))) allPrimes 
    (l:ls) <- StrL.lines `fmap` StrL.getContents 
    let numCases = readInt l 
    let cases = (take numCases ls) 
    sequence_ $ intersperse (putStrLn "") $ map (doLine factors) cases 

-- get and print all primes between the integers specified on a line. 
doLine :: [Integer] -> StrL.ByteString -> IO() 
doLine factors l = mapM_ print $ primesForLine factors l 


---------------------- pure code below this line ------------------------------ 

-- get all primes between the integers specified on a line. 
primesForLine :: [Integer] -> StrL.ByteString -> [Integer] 
primesForLine factors l = getPrimes factors range 
    where 
    range = rangeForLine l 

-- Generate a list of numbers to check, store it in list, and then check them... 
getPrimes :: [Integer] -> (Integer, Integer) -> [Integer] 
getPrimes factors range = filter (isPrime factors) (getCandidates range) 

-- generate list of candidate values based on upper and lower bound 
getCandidates :: (Integer, Integer) -> [Integer] 
getCandidates (propStart, propEnd) = list 
    where 
    list = if propStart < 3 
      then 2 : oddList 
      else oddList 
    oddList = [listStart, listStart + 2 .. propEnd] 
    listStart = if cleanStart `rem` 2 == 0 
       then cleanStart + 1 
       else cleanStart 
    cleanStart = if propStart < 3 
       then 3 
       else propStart 

-- A line always has the lower and upper bound separated by a space. 
rangeForLine :: StrL.ByteString -> (Integer, Integer) 
rangeForLine caseLine = start `seq` end `seq` (start, end) 
    where 
    [start, end] = (map readInteger $ StrL.words caseLine)::[Integer] 


-- read an Integer from a ByteString 
readInteger :: StrL.ByteString -> Integer 
readInteger x = 
    case StrL.readInteger x of Just (i,_) -> i 
          Nothing -> error "Unparsable Integer" 

-- read an Int from a ByteString 
readInt :: StrL.ByteString -> Int 
readInt x = 
    case StrL.readInt x of Just (i,_) -> i 
         Nothing -> error "Unparsable Int" 

-- generates all primes in a lazy way. 
allPrimes :: [Integer] 
allPrimes = ps (2:[3,5 .. ]) 
    where 
    ps (np:candidates) = -- np stands for New Prime 
     np : ps (filter (\n -> n `rem` np /= 0) candidates) 
    ps [] = error "this can't happen but is shuts up the compiler" 

-- Check to see if it is a prime by comparing against the factors. 
isPrime :: [Integer] -> Integer -> Bool 
isPrime factors val = all (\f -> val `rem` f /= 0) validFactors 
    where 
    validFactors = takeWhile (< ceil) factors 
    ceil = ((ceiling $ sqrt $ ((fromInteger val)::Double))) :: Integer 

내가 어떻게이 경고를 해결하는 아무 생각이 없습니다. 어떻게 시작합니까? 어셈블리를 컴파일하고 오류를 해결합니까? 경고는 무엇을 의미합니까?

답변

7

이것은 단지 (성가신) 경고이며 GHC가 정말로 원한다면 코드를 전문화 할 수 있음을 나타냅니다. GHC의 향후 버전은 기본적으로이 데이터를 방출하지 않을 것입니다. 어쨌든 당신이 할 수있는 일이 없기 때문입니다.

그들은 해가 없으며 오류가 아닙니다. 그들에 대해 걱정하지 마십시오.


직접 문제를 해결하기 위해 사용할 수있는 -w (경고를 억제) 대신 -Wall.

예. {-# OPTIONS_GHC -w #-} 파일에서 경고를 비활성화합니다.

또는 특수화 임계 값을 높이면 경고가 사라집니다. -fspec-constr-count=16

+0

알 수 있습니다. 내 특별한 문제는 SPOJ에 제출하려고하는데 컴파일 오류가 발생했다는 것입니다. 이 문제를 해결할 방법이 있습니까? 이 문제를 방지하기 위해 문제의 코드를 격리하고 다시 쓸 수 있습니까? SPOJ는 ghc 10.4.2를 사용합니다. –

+1

'-w' 대신'-w' (경고 무시)를 사용할 수 있습니까? 예 : 파일'{- # OPTIONS_GHC -w # -}'에. 또는 임계 값을 높이십시오 (예 : '-fspec-constr-count = 16' –

+0

-O2 플래그를 꺼내면 경고가 없습니다. 테스트 파일에서 시간이 6.5 초에서 10.5 초로 바뀌고 SPOJ에 시간 제한을 두지 않습니다. –