Created
September 5, 2011 01:31
-
-
Save emonkak/1193860 to your computer and use it in GitHub Desktop.
AnimasExample.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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