|
1 | 1 | module Data.Bifunctor.Joker where
|
2 | 2 |
|
3 |
| -import Control.Applicative (class Applicative, pure) |
4 |
| -import Control.Apply (class Apply, (<*>)) |
| 3 | +import Prelude |
| 4 | + |
5 | 5 | import Control.Biapplicative (class Biapplicative)
|
6 | 6 | import Control.Biapply (class Biapply)
|
7 |
| -import Control.Semigroupoid ((<<<)) |
8 | 7 |
|
9 | 8 | import Data.Bifunctor (class Bifunctor)
|
10 |
| -import Data.Functor (class Functor, map) |
| 9 | +import Data.Newtype (class Newtype) |
11 | 10 |
|
12 | 11 | -- | Make a `Functor` over the second argument of a `Bifunctor`
|
13 | 12 | newtype Joker g a b = Joker (g b)
|
14 | 13 |
|
15 |
| --- | Remove the `Joker` constructor. |
16 |
| -runJoker :: forall g a b. Joker g a b -> g b |
17 |
| -runJoker (Joker gb) = gb |
| 14 | +derive instance newtypeJoker :: Newtype (Joker g a b) _ |
| 15 | + |
| 16 | +derive newtype instance eqJoker :: Eq (g b) => Eq (Joker g a b) |
| 17 | + |
| 18 | +derive newtype instance ordJoker :: Ord (g b) => Ord (Joker g a b) |
| 19 | + |
| 20 | +instance showJoker :: Show (g b) => Show (Joker g a b) where |
| 21 | + show (Joker x) = "(Joker " <> show x <> ")" |
18 | 22 |
|
19 |
| -instance functorJoker :: (Functor g) => Functor (Joker g a) where |
20 |
| - map g = Joker <<< map g <<< runJoker |
| 23 | +instance functorJoker :: Functor g => Functor (Joker g a) where |
| 24 | + map g (Joker a) = Joker (map g a) |
21 | 25 |
|
22 |
| -instance bifunctorJoker :: (Functor g) => Bifunctor (Joker g) where |
23 |
| - bimap _ g = Joker <<< map g <<< runJoker |
| 26 | +instance bifunctorJoker :: Functor g => Bifunctor (Joker g) where |
| 27 | + bimap _ g (Joker a) = Joker (map g a) |
24 | 28 |
|
25 |
| -instance biapplyJoker :: (Apply g) => Biapply (Joker g) where |
| 29 | +instance biapplyJoker :: Apply g => Biapply (Joker g) where |
26 | 30 | biapply (Joker fg) (Joker xy) = Joker (fg <*> xy)
|
27 | 31 |
|
28 |
| -instance biapplicativeJoker :: (Applicative g) => Biapplicative (Joker g) where |
| 32 | +instance biapplicativeJoker :: Applicative g => Biapplicative (Joker g) where |
29 | 33 | bipure _ b = Joker (pure b)
|
0 commit comments