Skip to content

Instantly share code, notes, and snippets.

@akhileshs
Created April 29, 2017 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhileshs/58c4becfa4dd7243ed4b62264cfe125e to your computer and use it in GitHub Desktop.
Save akhileshs/58c4becfa4dd7243ed4b62264cfe125e to your computer and use it in GitHub Desktop.
import Control.Monad
class Profunctor p where
dimap :: (a -> b) -> (c -> d) -> p b c -> p a d
-- lmap :: (a -> b) -> p b c -> p a c
-- rmap :: (c -> d) -> p b c -> p b d
instance Profunctor (->) where
-- dimap :: (a -> b) -> (c -> d) -> (->) b c -> (->) a d
dimap ab cd bc = cd . bc . ab
newtype Kleisli m b c = Kleisli { runKleisli :: b -> m c }
instance Monad m => Profunctor (Kleisli m) where
-- dimap :: (a -> b) -> (c -> d) -> Kleisli m b c -> Kleisli m a d
dimap ab cd (Kleisli bmc) =
Kleisli (liftM cd . bmc . ab)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment