我从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/