Last active
June 17, 2019 18:58
-
-
Save monadplus/c8572f8685786d67d48efd847045d339 to your computer and use it in GitHub Desktop.
Data.Profunctor
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
-- Source: https://hackage.haskell.org/package/profunctors-5.4/docs/Data-Profunctor.html | |
class Profunctor p where | |
-- dimap | lmap, rmap | |
dimap :: (a -> b) -> (c -> d) -> p b c -> p a d | |
lmap :: (a -> b) -> p b c -> p a c | |
rmap :: (b -> c) -> p a b -> p a c | |
class Profunctor p => Strong p where | |
-- first' | second' | |
first' :: p a b -> p (a, c) (b, c) | |
second' :: p a b -> p (c, a) (c, b) | |
class Profunctor p => Choice p where | |
-- left' | right' | |
left' :: p a b -> p (Either a c) (Either b c) | |
righ' :: p a b -> p (Either c a) (Either c b) | |
class Profunctor p => Closed p where | |
closed :: p a b -> p (x -> a) (x -> b) | |
class (Traversing p, Closed p) => Mapping p where | |
map' :: Functor f => p a b -> p (f a) (f b) | |
roam :: (forall f. (Distributive f, Applicative f) => (a -> f b) -> s -> f t) -> p a b -> p s t | |
class Profunctor p => Costrong p where | |
-- unfirst | unsecond | |
unfirst :: p (a, d) (b, d) -> p a b | |
unsecond :: p (d, a) (d, b) -> p a b | |
class Profunctor p => Cochoice p where | |
-- unleft | unright | |
unleft :: p (Either a d) (Either b d) -> p a b | |
unright :: p (Either d a) (Either d b) -> p a b | |
-- ### Common Profunctors | |
-- Lift a Functor into a Profunctor (forwards) | |
newtype Start f d c = Start { runStart :: d -> f c } | |
-- Lift a Functor into a Profunctor (backwards) | |
newtype Costart f d c = Costart { runStart :: f d -> c } | |
-- Wrap an arrow for use as a Profunctor | |
newtype WrappedArrow p a b = WrapArrow { unwrapArrow :: p a b } | |
-- Const for arrows | |
newtype Forget r a b = Forget { runForget :: a -> r } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment