Created
November 25, 2018 14:35
-
-
Save lemastero/01e5d0c1174b05f33c6181dad49e58a7 to your computer and use it in GitHub Desktop.
Simple Haskell implementation for Profunctor and Strong Profunctor to analyse Strong Profunctor laws
This file contains hidden or 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
swap (a, b) = (b, a) | |
class Profunctor p where | |
dimap :: (aa -> a) -> (b -> bb) -> p a b -> p aa bb | |
lmap :: (aa -> a) -> p a b -> p aa b | |
lmap f = dimap f id | |
rmap :: (b -> bb) -> p a b -> p a bb | |
rmap = dimap id | |
instance Profunctor (->) where | |
dimap aa bb ab = bb . ab . aa | |
class Profunctor p => Strong p where | |
first :: p a b -> p (a, c) (b, c) | |
first = dimap swap swap . second | |
second :: p a b -> p (c, a) (c, b) | |
second = dimap swap swap . first | |
instance Strong (->) where | |
first ab = \(a,c) -> (ab a, c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment