Created
February 20, 2018 23:03
-
-
Save djleonskennedy/e2a2b02386c036fcce66c374d381b5d6 to your computer and use it in GitHub Desktop.
haskell monad laws
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
-- 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