production haskell
Reid Draper @reiddraper
wrangling the internet of things with haskell production haskell - - PowerPoint PPT Presentation
wrangling the internet of things with haskell production haskell Reid Draper @reiddraper production haskell Reid Draper @reiddraper production haskell today production haskell at helium 12 months in lowest defect rate lowest defect rate
Reid Draper @reiddraper
Reid Draper @reiddraper
12 months in
haskellstack.org
github.com/reiddraper/ordeal
app assets images favicon.ico javascript site.js stylesheet site.css bin app
propEvent :: Event -> Bool propEvent a = Just a == decode (encode a)
Event roundtrips in JSON: FAIL (0.04s) *** Failed! Falsifiable (after 1 test): Event {_severity = Error, _facility = Unspecified, _sampled = 1894-02-22 00:00:04.5986 UTC, _eventDetails = ElementDisconnect {_elementMAC = 8ec52584b2c82424}, _eventMessage = Nothing, _originator = http://www.ietf.org/rfc/rfc2396.txt, _reference = Just http://www.ietf.org/rfc/rfc2396.txt }
Event roundtrips in JSON: FAIL (0.04s) *** Failed! Falsifiable (after 1 test): Event {_severity = Error, _facility = Unspecified, _sampled = 1894-02-22 00:00:04.5986 UTC, _eventDetails = ElementDisconnect {_elementMAC = 8ec52584b2c82424}, _eventMessage = Nothing, _originator = http://www.ietf.org/rfc/rfc2396.txt, _reference = Just http://www.ietf.org/rfc/rfc2396.txt }
ghci> t 1894-02-22 00:00:04.5986 UTC ghci> Data.Aeson.encode t "\"1894-02-22T00:00:04.598Z\""
github.com/helium/postgresql-transactional
lookupUser emailAddress = queryFirst [emailAddress] [sql| SELECT id, email, name, timezone FROM user_account WHERE email = ? |]
foo
foo bar
foo bar baz
foo bar baz quz
foo bar baz quz buz
foo bar baz quz buz fiz
BEGIN BEGIN COMMIT COMMIT
BEGIN BEGIN COMMIT COMMIT
BEGIN BEGIN COMMIT COMMIT
WARNING: there is already a transaction in progress WARNING: there is no transaction in progress
foo bar baz quz buz fiz
foo bar baz quz buz fiz
foo bar baz quz buz
lookupUser :: Connection -> Text -> IO (Maybe User) lookupUser connection emailAddress = queryFirst [emailAddress] [sql| SELECT id, email, name, timezone FROM user_account WHERE email = ? |] connection
createUser :: Connection
createOrganization :: Connection
addUserToOrganization :: Connection
createUserAndOrganization :: Connection
createUserAndOrganization connection newUser = withTransaction connection $ do let newOrganization = NewOrganization (newUser ^. name) user <- createUser connection newUser
addUserToOrganization connection user org
createUserAndOrganization :: Connection
createUserAndOrganization connection newUser = do let newOrganization = NewOrganization (newUser ^. name) user <- createUser connection newUser
addUserToOrganization connection user org
withTransaction conn $ do createUserAndOrganization conn newUser somethingElse conn
lookupUser :: Connection -> Text -> IO (Maybe User) lookupUser :: Text -> PGTransaction (Maybe User)
runPGTransaction :: PGTransaction a
createUserAndOrganization :: NewUser
createUserAndOrganization newUser = let newOrganization = NewOrganization (newUser ^. name) user <- createUser newUser
addUserToOrganization user org foo = do createUserAndOrganization newUser somethingElse runPGTransaction foo connection
notAllowed = do user <- createUser newUser someSlowSideEffectingThing return user
notAllowed = do user <- createUser newUser someSlowSideEffectingThing :: IO () return user
github.com/helium/postgresql-transactional