Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access Graphics.Gloss Event type in Haskell?

Tags:

haskell

gloss

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?

like image 397
James McNeill Avatar asked Nov 11 '22 20:11

James McNeill


1 Answers

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.

like image 176
Jon Purdy Avatar answered Nov 23 '22 05:11

Jon Purdy