Skip to content

Instantly share code, notes, and snippets.

@swr1bm86
Last active April 28, 2017 09:16
Show Gist options
  • Save swr1bm86/23bb7d7672b1d0c5c62f6c43c6375e5e to your computer and use it in GitHub Desktop.
Save swr1bm86/23bb7d7672b1d0c5c62f6c43c6375e5e to your computer and use it in GitHub Desktop.
Function (Reader) Monad
foo :: Int -> Int
foo a = a + 1
bar :: Int -> Int
bar a = a - 1
foobar' :: Int -> [Int]
foobar' = sequence [foo, bar]
foobar :: Int -> Int
foobar = sum <$> sequence [foo, bar]
foo :: Int -> Int
foo a = a
:t fmap Just foo => fmap Just foo :: Int -> Maybe Int
foo :: Int -> Maybe Int
foo a = Just a
:t (fmap . fmap) Just foo => (fmap . fmap) Just foo :: Int -> Maybe (Maybe Int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment