5

I'm attempting to use the Gloss library's play function, which takes an event-handling function whose first argument is of type Event (according to the Hackage documentation). I'm working on Windows with GHC 7.6.3 and Gloss 1.8.0.1.

Here's a sketch of what I'm trying to do:

import Graphics.Gloss

type GameState = [Int]

handleInputEvent :: Event -> GameState -> GameState
handleInputEvent _ = id -- Just stubbed in for now

The compiler error is:

Not in scope: type constructor or class `Event'

If I go into WinGHCI and import Graphics.Gloss and ask it for the type signature of play, it looks like this:

play ::
  Display
  -> Color
  -> Int
  -> world
  -> (world -> Picture)
  -> (gloss-1.8.0.1:Graphics.Gloss.Internals.Interface.Event.Event
      -> world -> world)
  -> (Float -> world -> world)
  -> IO ()

I'm guessing this has something to do with the name Event clashing with some other module, and thus not being imported in the same way as other symbols from Gloss.

How do I talk to Haskell about Gloss' Event?

Helmut Grohne
  • 6,578
  • 2
  • 31
  • 67

1 Answers1

1

If you follow the link on Hackage in the type signature of play, and find that Event is exported from Graphics.Gloss.Interface.Pure.Game, then simply import that module.

Jon Purdy
  • 53,300
  • 8
  • 96
  • 166
  • Thank you! I got home this evening and started going through the code for the Gloss library, importing various things, and figured that out. – James McNeill Oct 13 '13 at 04:41
  • I didn't understand the documentation, I guess; the play function on there is visible without importing Graphics.Gloss.Interface.Pure.Game, so I assumed the rest of the symbols in there would also be visible. – James McNeill Oct 13 '13 at 04:42
  • 1
    @user5014: Yeah, generally a top-level module like this should re-export the definitions of types that it expects clients to use. This was probably an oversight. – Jon Purdy Oct 13 '13 at 08:36