Skip to content

Instantly share code, notes, and snippets.

@alistair
Created March 5, 2015 02:09
Show Gist options
  • Save alistair/b9db9ab3fa6e6dd0cf12 to your computer and use it in GitHub Desktop.
Save alistair/b9db9ab3fa6e6dd0cf12 to your computer and use it in GitHub Desktop.
#haskell
foldr (.) id [inc, inc, inc] $ 0
data Event
= AccountCreated Email
| AccountLoggedIn
| Start
-- .....
foldEvents :: [Event] -> Event
foldEvents = foldl' eval Start
eval :: Event -> Event -> Event
eval Start (AccountCreated email) = undefined
-- patterns ....
class Database a where
getAll :: Id -> a [Event]
instance Database IO where
getAll = --- magic happens here
instance Database State where
getAll = -- get from state
main :: IO ()
main = getDbResult
test :: User -> Test ()
test user = runState getDbResults user
getDbResults user = do
events <- getAll user
return $ foldEvents events
- Set up haskell dev env
Download GHC 7.8.4 with your package manager
mkdir Project
cd Project
cabal init
cabal sandbox init
cabal configure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment