Skip to content

Instantly share code, notes, and snippets.

@chessai
Last active November 13, 2018 21:13
Show Gist options
  • Save chessai/0e85a0d6f783cee9535b2790a943fd50 to your computer and use it in GitHub Desktop.
Save chessai/0e85a0d6f783cee9535b2790a943fd50 to your computer and use it in GitHub Desktop.
import Data.Functor.Compose
doubleFmap :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b)
doubleFmap = fmap . fmap
fooMonad :: (Monad f, Functor g) => f (a -> b) -> f (g a) -> f (g b)
fooMonad fab fga = fab >>= \f -> doubleFmap f fga
fooApplicative :: (Applicative f, Applicative g) => f (a -> b) -> f (g a) -> f (g b)
fooApplicative fab fga = getCompose (Compose (fmap pure fab) <*> Compose fga)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment