Skip to content

Instantly share code, notes, and snippets.

@vijayanant
Last active January 17, 2020 13:54
Show Gist options
  • Save vijayanant/fdb8e772546e3d3a201bcd5bf64334f4 to your computer and use it in GitHub Desktop.
Save vijayanant/fdb8e772546e3d3a201bcd5bf64334f4 to your computer and use it in GitHub Desktop.
Choose Wisely
-- 1 + 2
-- (+) 1 2
-- + (Just 1) (Just 2)
-- Monadic desugared
(Just 1) >>= (\x -> (Just 2) >>= \y -> return (x+y))
-- Monadic sugar
do {x <- Just 1; y <- Just 2; return (x+y)}
-- Functor + Applicative
fmap (+) (Just 1) <*> (Just 2)
-- Applicative
pure (+) <*> (Just 1) <*> (Just 2)
-- Applicative
(+) <$> (Just 1) <*> (Just 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment