Skip to content

Instantly share code, notes, and snippets.

@benaryorg
Last active September 20, 2017 22:55
Show Gist options
  • Save benaryorg/62d3283fb50701ac6a51f3a811c4f7e9 to your computer and use it in GitHub Desktop.
Save benaryorg/62d3283fb50701ac6a51f3a811c4f7e9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env stack
-- stack --install-ghc runghc -- -Wno-tabs
data Event
= Noop
| Noise
| Pats
deriving (Show,Read)
data Action
= Sleep
| Purr
| Meow
deriving (Show,Read)
main :: IO ()
main = interact (unlines . map show . eventLoop . map read . lines)
eventLoop :: [Event] -> [Action]
eventLoop = live cat
live :: (Event -> [Action]) -> [Event] -> [Action]
live style = concat . map style
cat :: Event -> [Action]
cat Pats = [Purr]
cat Noop = [Sleep]
cat Noise = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment