File tree Expand file tree Collapse file tree 6 files changed +106
-0
lines changed
Expand file tree Collapse file tree 6 files changed +106
-0
lines changed Original file line number Diff line number Diff line change 2222 " package.json"
2323 ],
2424 "dependencies" : {
25+ "purescript-contravariant" : " ^3.0.0" ,
2526 "purescript-distributive" : " ^3.0.0" ,
2627 "purescript-either" : " ^3.0.0" ,
2728 "purescript-tuples" : " ^4.0.0"
Original file line number Diff line number Diff line change 1+ module Data.Profunctor.Clown where
2+
3+ import Prelude
4+
5+ import Data.Profunctor (class Profunctor )
6+ import Data.Newtype (class Newtype )
7+ import Data.Functor.Contravariant (class Contravariant , cmap )
8+
9+ -- | Makes a trivial `Profunctor` for a `Contravariant` functor.
10+ newtype Clown f a b = Clown (f a )
11+
12+ derive instance newtypeClown :: Newtype (Clown f a b ) _
13+ derive newtype instance eqClown :: Eq (f a ) => Eq (Clown f a b )
14+ derive newtype instance ordClown :: Ord (f a ) => Ord (Clown f a b )
15+
16+ instance showClown :: Show (f a ) => Show (Clown f a b ) where
17+ show (Clown x) = " (Clown " <> show x <> " )"
18+
19+ instance functorClown :: Functor (Clown f a ) where
20+ map _ (Clown a) = Clown a
21+
22+ instance profunctorClown :: Contravariant f => Profunctor (Clown f ) where
23+ dimap f g (Clown a) = Clown (cmap f a)
Original file line number Diff line number Diff line change 1+ module Data.Profunctor.Cowrap where
2+
3+ import Prelude
4+
5+ import Data.Newtype (class Newtype )
6+ import Data.Functor.Contravariant (class Contravariant )
7+ import Data.Profunctor (class Profunctor , lmap )
8+
9+ -- | Provides a `Contravariant` over the first argument of a `Profunctor`.
10+ newtype Cowrap p b a = Cowrap (p a b )
11+
12+ derive instance newtypeCowrap :: Newtype (Cowrap p b a ) _
13+ derive newtype instance eqCowrap :: Eq (p a b ) => Eq (Cowrap p b a )
14+ derive newtype instance ordCowrap :: Ord (p a b ) => Ord (Cowrap p b a )
15+
16+ instance showCowrap :: Show (p a b ) => Show (Cowrap p b a ) where
17+ show (Cowrap x) = " (Cowrap " <> show x <> " )"
18+
19+ instance contravariantCowrap :: Profunctor p => Contravariant (Cowrap p b ) where
20+ cmap f (Cowrap a) = Cowrap (lmap f a)
Original file line number Diff line number Diff line change 1+ module Data.Profunctor.Join where
2+
3+ import Prelude
4+
5+ import Data.Functor.Invariant (class Invariant )
6+ import Data.Newtype (class Newtype )
7+ import Data.Profunctor (class Profunctor , dimap )
8+
9+ -- | Turns a `Profunctor` into a `Invariant` functor by equating the two type
10+ -- | arguments.
11+ newtype Join p a = Join (p a a )
12+
13+ derive instance newtypeJoin :: Newtype (Join p a ) _
14+ derive newtype instance eqJoin :: Eq (p a a ) => Eq (Join p a )
15+ derive newtype instance ordJoin :: Ord (p a a ) => Ord (Join p a )
16+
17+ instance showJoin :: Show (p a a ) => Show (Join p a ) where
18+ show (Join x) = " (Join " <> show x <> " )"
19+
20+ instance invariantJoin :: Profunctor p => Invariant (Join p ) where
21+ imap f g (Join a) = Join (dimap g f a)
Original file line number Diff line number Diff line change 1+ module Data.Profunctor.Joker where
2+
3+ import Prelude
4+
5+ import Data.Profunctor (class Profunctor )
6+ import Data.Newtype (class Newtype )
7+
8+ -- | Makes a trivial `Profunctor` for a covariant `Functor`.
9+ newtype Joker f a b = Joker (f b )
10+
11+ derive instance newtypeJoker :: Newtype (Joker f a b ) _
12+ derive newtype instance eqJoker :: Eq (f b ) => Eq (Joker f a b )
13+ derive newtype instance ordJoker :: Ord (f b ) => Ord (Joker f a b )
14+
15+ instance showJoker :: Show (f b ) => Show (Joker f a b ) where
16+ show (Joker x) = " (Joker " <> show x <> " )"
17+
18+ instance functorJoker :: Functor f => Functor (Joker f a ) where
19+ map f (Joker a) = Joker (map f a)
20+
21+ instance profunctorJoker :: Functor f => Profunctor (Joker f ) where
22+ dimap f g (Joker a) = Joker (map g a)
Original file line number Diff line number Diff line change 1+ module Data.Profunctor.Wrap where
2+
3+ import Prelude
4+
5+ import Data.Newtype (class Newtype )
6+ import Data.Profunctor (class Profunctor , rmap )
7+
8+ -- | Provides a `Functor` over the second argument of a `Profunctor`.
9+ newtype Wrap p a b = Wrap (p a b )
10+
11+ derive instance newtypeWrap :: Newtype (Wrap p a b ) _
12+ derive newtype instance eqWrap :: Eq (p a b ) => Eq (Wrap p a b )
13+ derive newtype instance ordWrap :: Ord (p a b ) => Ord (Wrap p a b )
14+
15+ instance showWrap :: Show (p a b ) => Show (Wrap p a b ) where
16+ show (Wrap x) = " (Wrap " <> show x <> " )"
17+
18+ instance functorWrap :: Profunctor p => Functor (Wrap p a ) where
19+ map f (Wrap a) = Wrap (rmap f a)
You can’t perform that action at this time.
0 commit comments