fumieval / free-game

The free game engine
http://hackage.haskell.org/package/free-game
BSD 3-Clause "New" or "Revised" License
64 stars 15 forks source link

An unified input API #7

Closed fumieval closed 11 years ago

fumieval commented 11 years ago

data Input x where
    Not :: Input Bool -> Input Bool
    Previous :: Input a -> Input a
    (:&:) :: Input Bool -> Input Bool -> Input Bool
    KeyChar :: Char -> Input Bool

down k = k :&: Not (Previous k))

gameMain = do
    z <- input (down (KeyChar 'Z'))
fumieval commented 11 years ago

We don't require GADTs. Just use Free Applicative:

data InputBase = Key Char (Bool -> a) | Mouse (V2 -> a) deriving Functor

type Input = Ap Input

key :: Char -> Input Bool
key ch = liftAp $ Key ch id

mouse :: Input V2
mouse = liftAp $ Mouse ch id
fumieval commented 11 years ago

Done.