From e33daf5d6e0529e8754da72e61593a1e59e52d68 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sat, 17 Jun 2017 23:13:17 +0100 Subject: [PATCH] Add `hoist` functions --- src/Data/Profunctor/Clown.purs | 3 +++ src/Data/Profunctor/Costar.purs | 5 ++++- src/Data/Profunctor/Joker.purs | 3 +++ src/Data/Profunctor/Star.purs | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Data/Profunctor/Clown.purs b/src/Data/Profunctor/Clown.purs index cd90ab6..e6544e7 100644 --- a/src/Data/Profunctor/Clown.purs +++ b/src/Data/Profunctor/Clown.purs @@ -21,3 +21,6 @@ instance functorClown :: Functor (Clown f a) where instance profunctorClown :: Contravariant f => Profunctor (Clown f) where dimap f g (Clown a) = Clown (cmap f a) + +hoistClown :: forall f g a b. (f ~> g) -> Clown f a b -> Clown g a b +hoistClown f (Clown a) = Clown (f a) diff --git a/src/Data/Profunctor/Costar.purs b/src/Data/Profunctor/Costar.purs index fcc53df..0d54843 100644 --- a/src/Data/Profunctor/Costar.purs +++ b/src/Data/Profunctor/Costar.purs @@ -9,7 +9,7 @@ import Data.Distributive (class Distributive, distribute) import Data.Either (Either(..), either) import Data.Functor.Invariant (class Invariant, imapF) import Data.Newtype (class Newtype) -import Data.Profunctor (class Profunctor) +import Data.Profunctor (class Profunctor, lmap) import Data.Profunctor.Closed (class Closed) import Data.Profunctor.Cochoice (class Cochoice) import Data.Profunctor.Costrong (class Costrong) @@ -73,3 +73,6 @@ instance cochoiceCostar :: Applicative f => Cochoice (Costar f) where instance closedCostar :: Functor f => Closed (Costar f) where closed (Costar f) = Costar \g x -> f (map (_ $ x) g) + +hoistCostar :: forall f g a b. (g ~> f) -> Costar f a b -> Costar g a b +hoistCostar f (Costar g) = Costar (lmap f g) diff --git a/src/Data/Profunctor/Joker.purs b/src/Data/Profunctor/Joker.purs index fd0d872..9cc3a62 100644 --- a/src/Data/Profunctor/Joker.purs +++ b/src/Data/Profunctor/Joker.purs @@ -20,3 +20,6 @@ instance functorJoker :: Functor f => Functor (Joker f a) where instance profunctorJoker :: Functor f => Profunctor (Joker f) where dimap f g (Joker a) = Joker (map g a) + +hoistJoker :: forall f g a b. (f ~> g) -> Joker f a b -> Joker g a b +hoistJoker f (Joker a) = Joker (f a) diff --git a/src/Data/Profunctor/Star.purs b/src/Data/Profunctor/Star.purs index 75e8bf6..d08997f 100644 --- a/src/Data/Profunctor/Star.purs +++ b/src/Data/Profunctor/Star.purs @@ -77,3 +77,6 @@ instance choiceStar :: Applicative f => Choice (Star f) where instance closedStar :: Distributive f => Closed (Star f) where closed (Star f) = Star \g -> distribute (f <<< g) + +hoistStar :: forall f g a b. (f ~> g) -> Star f a b -> Star g a b +hoistStar f (Star g) = Star (f <<< g)