使用 ghc 编译 Haskell 代码时出现专业化警告

2024-02-24

尝试编译时出现以下错误

$ ghc --make -O2 -Wall -fforce-recomp

[1 of 1] 编译主程序 ( isPrimeSmart.hs、isPrimeSmart.o ) 规格构造 函数 `$wa{v s2we} [lid]' 有两种调用模式,但限制为 1 使用 -fspec-constr-count=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

我不知道如何解决这个警告。我该如何开始?我是否编译为汇编并匹配错误?这个警告到底意味着什么?


这些只是(烦人的)警告,表明如果您确实愿意,GHC 可以对您的代码进行进一步的专业化。 GHC 的未来版本可能不会默认发出此数据,因为无论如何您都无能为力。

它们是无害的,也不是错误。别担心他们。


要直接解决问题,您可以使用-w(抑制警告)而不是-Wall.

例如。在一个文件中{-# OPTIONS_GHC -w #-}将禁用警告。

或者,增加专业化阈值将使警告消失,例如-fspec-constr-count=16

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 ghc 编译 Haskell 代码时出现专业化警告 的相关文章

随机推荐

  • Google Places API 未返回印度的任何结果

    https maps googleapis com maps api place search json location 28 635704 77 224982 radius 50000 types restaurant language
  • SQL Server中删除表和删除表有什么区别?

    在 SQL Server 中 以下两者有什么区别 右键单击数据库对象 表 视图 并选择 删除表 即将表脚本编写为 gt DROP To gt New Query Editor Window 右键单击数据库对象 表 视图 并选择删除 我尝试了
  • Chrome 不缓存 css 文件。缓存适用于 .js/.png 文件。

    我观察到 CSS 文件没有在 Chrome 浏览器上缓存 我的应用程序是由 Angular CLI 构建的 所有必需的缓存控制标头和 Expires 标头均设置为 5 分钟 Accept Ranges bytes Cache Control
  • 在 R 中绘制多行文本框

    我正在使用 R 创建多图布局插图 并且能够在其中一个图中创建多行文本框会很方便 我熟悉使用 Sweave 来组合图像 文本和 R 代码 但是由于各种原因 我需要将其作为在 R 中生成的单页图 因此需要绘制文本框而不是使用 Latex 标记
  • GET_TASKS 权限已弃用

    我有一个使用此权限的安全应用程序 App Locker android permission GET TASKS 在 android Lollipop 中 此权限已被弃用 我希望我的应用程序可以在 21 API 中运行 谁能指导我怎么做 T
  • JPADatabase 的 jooq codegen 无法正常工作

    我在 JPADatabase 中使用 jooq codegen 时遇到问题 我经历过这个post https stackoverflow com questions 42968155 unable to generate jooq clas
  • 如何使用 javascript/jquery 获取具有特定文本的元素的类名称?

    我需要一种 JavaScript 或 jQuery 方法来通过 DIV 元素包含的文本提取 DIV 元素的类名 让我们举例说明 如果我有的话 我们可以说以下代码 div class className UniqueText div 我需要知
  • 用于设置主页功能的通用 JavaScript [重复]

    这个问题在这里已经有答案了 是否有任何适用于几乎所有浏览器的 javascript 将网页设置为主页 我正在使用下面的一种 但它只适用于 i e 和 mozilla var flag false function setHomepage w
  • Scalac 挂在 RegexParser 的阶段类型上

    我有一个 scala 程序 其中有一个解析器组合器 这是通过扩展来完成的scala util parsing combinator RegexParsers 我使用 Scala 2 10 开发它 一切正常 昨天我将系统升级到了 Scala
  • 播放前检测浏览器/设备是否可以内嵌播放 HTML5 视频

    我知道我可以检查一下navigator userAgent如果设备是 iPhone 但还有其他设备 其中一些我不知道哪些设备会在其自己的播放器中播放视频 可以列出所有不内联播放视频的浏览器 设备 但我想知道是否还有其他解决方案 JavaSc
  • 创建 iOS 应用程序 (Xcode) 时,如何关闭自动图标“凝胶”

    有没有办法去掉创建 iPhone 应用程序时自动添加到图标的突出显示 或者我必须在 PS 中手动补偿 Thanks Set UIPrerenderedIcon to YES在你的 Info plist 中 欲了解更多信息 请参阅 信息属性列
  • 将 pandas 数据框中的 datetime64 列拆分为日期和时间列

    如果我有一个数据框 第一列是 datetime64 列 如何将此列拆分为 2 个新列 日期列和时间列 这是到目前为止我的数据和代码 DateTime Actual Consensus Previous 20140110 13 30 00 7
  • R 如何将“-17+3”等简单函数分离为数字,例如“-17”和“3”

    我的数据就像 17 3 2 6 我需要做的是将每个数字分成两个数字 例如 17 3 变为 17 和 3 2 6 分为 2 和 6 通过使用 R 非常感谢 gregexpr http stat ethz ch R manual R devel
  • Fortran:哪种方法可以更快地更改数组的等级? (重塑与指针)

    当我们处理大型数组时 考虑数组的等级和形状变化的成本可能很重要 特别是当它在多个子例程 函数中发生几次时 我问题的主要目的是将数组的排名从第二更改为第一 反之亦然 为此 可以使用 重塑声明 指针变量 下面的代码展示了如何使用指针变量 pro
  • C++中双冒号的全名

    如果我有课 class A public A void print private int value A A value 0 void A print cout lt lt value lt lt endl 最后两行中 符号的完整名称是什
  • 如何使用messagebox输出调试信息

    我正在使用 MessageBox 尝试进行一些手动调试 这就是我所想出的全部 我应该如何使其工作 private void DisplayMessageBoxText MessageBox Show Alert Message 您可以使用写
  • 关于使用遗留代码的建议

    我需要一些关于如何使用遗留代码的建议 不久前 我接到的任务是向报告应用程序添加一些报告 2005 年用 Struts 1 编写的 没什么大不了的 但是代码相当混乱 没有使用Action形式 基本上代码就是一个巨大的action 里面有很多i
  • Dockerfile 中的 Mongorestore

    我想创建一个启动 mongo 服务器并自动从以前的版本恢复的 Docker 映像mongodump启动时 这是我的图像 Dockerfile FROM mongo COPY dump home dump CMD mongorestore h
  • 无法删除 Qt 布局的子布局中的小部件

    我正在使用 Windows 版 Qt 5 5 0 在用于登录和注册的对话框中 我使用 QVBoxLayout 作为对话框的主布局 并将 QGridLayout 添加到 mainLayout 当我单击 注册 按钮时 它将添加太多用于注册的 L
  • 使用 ghc 编译 Haskell 代码时出现专业化警告

    尝试编译时出现以下错误 ghc make O2 Wall fforce recomp 1 of 1 编译主程序 isPrimeSmart hs isPrimeSmart o 规格构造 函数 wa v s2we lid 有两种调用模式 但限制