Skip to content

Instantly share code, notes, and snippets.

@djleonskennedy
Created February 20, 2018 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djleonskennedy/e2a2b02386c036fcce66c374d381b5d6 to your computer and use it in GitHub Desktop.
Save djleonskennedy/e2a2b02386c036fcce66c374d381b5d6 to your computer and use it in GitHub Desktop.
haskell monad laws
-- Left identity
-- return x >>= f 'same as' f x
return 3 >>= (\x -> Just (x+100000))
-- Just 100003
(\x -> Just (x+100000)) 3
-- Just 100003
-- Right identity
-- m >>= return 'same as' m
Just "move on up" >>= (\x -> return x)
-- Just "move on up"
[1,2,3,4] >>= (\x -> return x)
-- [1,2,3,4]
putStrLn "Wah!" >>= (\x -> return x)
-- Wah!
-- Associativity
-- (m >>= f) >>= g `same as` m >>= (\x -> f x >>= g)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment