1

I switched from C++ to Haskell and use Gloss to make games. I wrote this valid code in a 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)

Then the command ghc main.hs answered:

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

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

It seems some functions are missing from my Gloss lib even though I have the latest version installed. For example, this code, "Game Event" from the gloss-examples package, compiles and runs perfectly (so beautiful):

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)
4

1 回答 1

7

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

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

扫描Gloss 的文档,看起来你正在寻找

rectangleWire :: Float -> Float -> PictureSource

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

于 2012-06-07T15:33:16.107 回答