Skip to content

Instantly share code, notes, and snippets.

@jhickner
Created March 3, 2013 09:33
Show Gist options
  • Save jhickner/5075463 to your computer and use it in GitHub Desktop.
Save jhickner/5075463 to your computer and use it in GitHub Desktop.
import Control.Monad
import Control.Applicative
import Control.Proxy
import System.IO
import Prelude hiding (Left, Right)
data Input = Up | Down | Left | Right | Invalid deriving Show
toInput :: Char -> Input
toInput c = case c of
'u' -> Up
'd' -> Down
'l' -> Left
'r' -> Right
_ -> Invalid
inputs :: Proxy p => Handle -> () -> Producer p Input IO ()
inputs h () = runIdentityP . forever $ lift (toInput <$> hGetChar h) >>= respond
printer :: (Proxy p, Show a) => () -> Consumer p a IO r
printer () = runIdentityP . forever $ request () >>= lift . print
main = do
hSetEcho stdin False
runProxy $ inputs stdin >-> printer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment