【问题标题】:Haskell code with Gloss lib doesn't compile带有 Gloss lib 的 Haskell 代码无法编译
【发布时间】:2012-06-07 15:20:59
【问题描述】:

我从 C++ 切换到 Haskell 并使用 Gloss 制作游戏。 我在 main.hs 中编写了这个有效代码:

import Graphics.Gloss.Interface.Pure.Game

events (EventKey (Char 'a') Down _ _) _ = RectangleWire 10 10
events _ x = x

main = play (InWindow "GameEvent" (700, 100) (10, 10))
    white
    100
    (Circle 10.0)
    id
    events
    (\_ world -> world)

然后命令ghc main.hs回答:

[1 of 1] Compiling Main             ( main.hs, main.o )

main.hs:3:43: Not in scope: data constructor `RectangleWire'

即使我安装了最新版本,我的 Gloss 库中似乎也缺少一些功能。例如,gloss-examples 包中的“Game Event”代码编译和运行完美(太漂亮了):

import Graphics.Gloss

-- | Display the last event received as text.
main
 = play (InWindow "GameEvent" (700, 100) (10, 10))
        white
        100
        ""
        (\str     -> Translate (-340) 0 $ Scale 0.1 0.1 $ Text str)
        (\event _ -> show event)
        (\_ world -> world)

【问题讨论】:

  • 好吧,如果它不编译显然是无效的。 AFAICS Graphics.Gloss.Interface.Pure.Game 不导出 RectangleWire
  • 那是因为RectangleWire 不存在。 Graphics.Gloss.Interface.Pure.Game 导入 Graphics.Gloss.Data.Picture 并因此导入 rectangleWire。我只是误读了函数的名称!有时,最好复制/粘贴...

标签: haskell compiler-errors gloss


【解决方案1】:

您的代码无法编译,因为您引用的数据构造函数 RectangleWire 不在范围内。错误表明这一点:

main.hs:3:43: Not in scope: data constructor `RectangleWire'

扫描documentation for Gloss,看起来你在找

rectangleWire :: Float -> Float -> PictureSource

以原点为中心的线框矩形,具有给定的宽度和高度。从Graphics.Gloss.Data.Picture导出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多