L01*_*man 1 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)
Run Code Online (Sandbox Code Playgroud)
然后命令ghc main.hs回答:
[1 of 1] Compiling Main ( main.hs, main.o )
main.hs:3:43: Not in scope: data constructor `RectangleWire'
Run Code Online (Sandbox Code Playgroud)
即使我安装了最新版本,我的Gloss lib似乎也缺少一些功能.例如,这个代码,来自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)
Run Code Online (Sandbox Code Playgroud)
您的代码无法编译,因为您引用的数据构造函数RectangleWire不在范围内.错误表明:
main.hs:3:43: Not in scope: data constructor `RectangleWire'
Run Code Online (Sandbox Code Playgroud)
rectangleWire :: Float -> Float -> PictureSource
Run Code Online (Sandbox Code Playgroud)
以原点为中心的线框矩形,具有给定的宽度和高度.出口自Graphics.Gloss.Data.Picture.