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)
Helmut Grohne
  • 6,578
  • 2
  • 31
  • 67
L01man
  • 1,521
  • 10
  • 27
  • 1
    Well, obviously it's not valid if it doesn't compile. AFAICS `Graphics.Gloss.Interface.Pure.Game` doesn't export `RectangleWire`. – Cat Plus Plus Jun 07 '12 at 15:25
  • That's because `RectangleWire` doesn't exist. `Graphics.Gloss.Interface.Pure.Game` imports `Graphics.Gloss.Data.Picture` and thus `rectangleWire`. I just misread the functions' name! Sometimes, it's better to copy/paste... – L01man Jun 08 '12 at 12:38

1 Answers1

7

Your code is failing to compile because a data constructor you refer to, RectangleWire is not in scope. The error indicates this:

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

Scanning the documentation for Gloss, it looks like you're looking for

rectangleWire :: Float -> Float -> PictureSource

A wireframe rectangle centered about the origin, with the given width and height. Exported from Graphics.Gloss.Data.Picture.

Don Stewart
  • 137,316
  • 36
  • 365
  • 468