Skip to content

Instantly share code, notes, and snippets.

@MaxwellBo
Last active December 18, 2018 04:45
Show Gist options
  • Save MaxwellBo/9ef5704b325e09afaffee050a91d9c91 to your computer and use it in GitHub Desktop.
Save MaxwellBo/9ef5704b325e09afaffee050a91d9c91 to your computer and use it in GitHub Desktop.
import Control.Monad
import Control.Applicative
-- Application operators LHS | RHS | RESULT
($) :: (a -> b) -> a -> b
(<$>) :: Functor f => (a -> b) -> f a -> f b
(<*>) :: Applicative f => f (a -> b) -> f a -> f b
(=<<) :: Monad m => (a -> m b) -> m a -> m b
(5+) $ 5 == 10
(5+) <$> Just 5 == Just 10
(5+) <$> Nothing == Nothing
Just (5+) <*> Just 5 == Just 10
Just (5+) <*> Nothing == Nothing
Nothing <*> Just 5 == Nothing
(+) <$> Just 5 <*> Just 5 == Just 10
(+) <$> Just 5 <*> Nothing == Nothing
(+) <$> Nothing <*> Just 5 == Nothing
(\x -> Just (x + 5)) =<< Just 5 == Just 10
(\x -> Just (x + 5)) =<< Nothing == Nothing
(\x -> Nothing) =<< Just 5 == Nothing
-- Composition operators LHS | RHS | RESULT
(.) :: (b -> c) -> (a -> b) -> (a -> c)
fmap.fmap :: Functor f => (b -> c) -> f (a -> b) -> f (a -> c)
liftA2 (.) :: Applicative f => f (b -> c) -> f (a -> b) -> f (a -> c)
(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> (a -> m c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment