Skip to content

Instantly share code, notes, and snippets.

@emonkak
Created September 5, 2011 01:31
Show Gist options
  • Save emonkak/1193860 to your computer and use it in GitHub Desktop.
Save emonkak/1193860 to your computer and use it in GitHub Desktop.
AnimasExample.hs
{-# LANGUAGE Arrows #-}
import Control.Applicative
import Data.Char
import FRP.Animas
import System.IO
initialize :: IO (Event Char)
initialize = do
hSetBuffering stdin NoBuffering
hSetBuffering stdout NoBuffering
hSetEcho stdin False
Event <$> getChar
sense :: Bool -> IO (DTime, Maybe (Event Char))
sense _ = do
input <- getChar
return (1.0, Just $ Event input)
actuate :: Bool -> (Time, String) -> IO Bool
actuate _ (time, input)
| isSpace $ head input = do
putStrLn $ reverse input
return True
| otherwise = do
putStr $ show time ++ ":\t"
putStrLn [head input]
return False
process :: SF (Event Char) (Time, String)
process = proc event -> do
input <- accumHold "" -< (:) <$> event
time <- localTime -< ()
returnA -< (time, input)
main = reactimate initialize sense actuate process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment