Created
March 5, 2015 02:09
-
-
Save alistair/b9db9ab3fa6e6dd0cf12 to your computer and use it in GitHub Desktop.
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
#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