{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable #-} module GLDriver ( Driver(..) , SomeDriver(..) , Event , SomeEvent(..) , QuitEvent(..) , ResizeEvent(..) , fromEvent ) where import Data.Typeable class Driver a where initialized :: a -> Bool initGL :: a -> IO a deinitGL :: a -> IO () swapBuffers :: a -> IO () nextEvent :: a -> IO (Maybe SomeEvent) data SomeDriver = forall d. Driver d => SomeDriver d instance Driver SomeDriver where initialized (SomeDriver d) = initialized d initGL (SomeDriver d) = initGL d >>= return . SomeDriver deinitGL (SomeDriver d) = deinitGL d swapBuffers (SomeDriver d) = swapBuffers d nextEvent (SomeDriver d) = nextEvent d class Typeable a => Event a data SomeEvent = forall a. Event a => SomeEvent a fromEvent :: Event a => SomeEvent -> Maybe a fromEvent (SomeEvent a) = cast a data QuitEvent = QuitEvent deriving Typeable instance Event QuitEvent data ResizeEvent = ResizeEvent Int Int deriving Typeable instance Event ResizeEvent