haskell - 具有Gloss lib的Haskell代码无法编译

标签 haskell compiler-errors gloss

我从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”包中的“游戏事件”,可以完美地编译并运行(如此漂亮):
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)

最佳答案

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

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

扫描documentation for Gloss,好像您在寻找
rectangleWire :: Float -> Float -> PictureSource

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

关于haskell - 具有Gloss lib的Haskell代码无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10934788/

相关文章:

c++ - “类”在这里有一个先前的声明

opengl - 在 Ubuntu 上安装光泽(特别是 OpenGLRaw 依赖项)时出现 "* Missing C library: GL"

java - 意外类型所需变量找到的值

haskell - GHC 可以将二进制文件链接到 libc 实现,例如 uclibc(默认在 OpenWrt 中使用)吗?

haskell - 在 Haskell 中使用 Dynamic/fromDynamic 时是否可以恢复约束?

haskell - 为什么 Haskell 中的递归习语是 "' n+ 1' and ' n '"and not "'n' 和 'n-1' "?

arrays - 在C++中是否允许使用具有定义的const的数组?

Haskell Gloss,在动画功能中从控制台读取不会更新绘图

haskell - 如何在 haskell 中使用 ffmpeg-light 查找 mp4 元数据?

haskell - 对使用仿函数 <$> 的困惑