나는경고
$ 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
내가 어떻게이 경고를 해결하는 아무 생각이 없습니다. 어떻게 시작합니까? 어셈블리를 컴파일하고 오류를 해결합니까? 경고는 무엇을 의미합니까?
알 수 있습니다. 내 특별한 문제는 SPOJ에 제출하려고하는데 컴파일 오류가 발생했다는 것입니다. 이 문제를 해결할 방법이 있습니까? 이 문제를 방지하기 위해 문제의 코드를 격리하고 다시 쓸 수 있습니까? SPOJ는 ghc 10.4.2를 사용합니다. –
'-w' 대신'-w' (경고 무시)를 사용할 수 있습니까? 예 : 파일'{- # OPTIONS_GHC -w # -}'에. 또는 임계 값을 높이십시오 (예 : '-fspec-constr-count = 16' –
-O2 플래그를 꺼내면 경고가 없습니다. 테스트 파일에서 시간이 6.5 초에서 10.5 초로 바뀌고 SPOJ에 시간 제한을 두지 않습니다. –