Created
February 9, 2019 15:57
-
-
Save iurii-kyrylenko/ab0a6d867d92b093a82252a7dcfd3e35 to your computer and use it in GitHub Desktop.
Haskell/Profunctor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Profunctor p where | |
dimap :: (a -> b) -> (c -> d) -> p b c -> p a d | |
dimap f g = lmap f . rmap g | |
lmap :: (a -> b) -> p b c -> p a c | |
lmap f = dimap f id | |
rmap :: (b -> c) -> p a b -> p a c | |
rmap = dimap id | |
instance Profunctor (->) where | |
-- dimap :: (a -> b) -> (c -> d) -> (b -> c) -> (a -> d) | |
-- dimap ab cd bc = cd . bc . ab | |
-- lmap :: (a -> b) -> (b -> c) -> (a -> c) | |
-- lmap = flip (.) | |
-- lmap ab bc = dimap ab id bc | |
-- lmap ab = dimap ab id | |
lmap = flip dimap id | |
-- rmap :: (b -> c) -> (a -> b) -> (a -> c) | |
-- rmap = (.) | |
-- rmap bc ab = dimap ab id bc | |
-- rmap = flip (flip dimap id) | |
-- rmap bc ab = lmap ab bc | |
-- rmap = flip lmap | |
rmap = dimap id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment