Skip to content

Commit 5611e17

Browse files
authored
Refactor functors and related packages (#19)
This is part of a set of commits that rearrange the dependencies between multiple packages. The immediate motivation is to allow certain newtypes to be reused between `profunctor` and `bifunctors`, but this particular approach goes a little beyond that in two ways: first, it attempts to move data types (`either`, `tuple`) toward the bottom of the dependency stack; and second, it tries to ensure no package comes between `functors` and the packages most closely related to it, in order to open the possibility of merging those packages together (which may be desirable if at some point in the future additional newtypes are added which reveal new and exciting constraints on the module dependency graph).
1 parent 3c8718f commit 5611e17

File tree

3 files changed

+1
-46
lines changed

3 files changed

+1
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Breaking changes:
88
- Added support for PureScript 0.14 and dropped support for all previous versions (#15)
99

1010
New features:
11+
- This package no longer depends on the `purescript-contravariant` and `purescript-foldable-traversable` packages. Relevant instances have been moved to those packages. (#19)
1112

1213
Bugfixes:
1314

bower.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
"package.json"
2222
],
2323
"dependencies": {
24-
"purescript-contravariant": "master",
25-
"purescript-foldable-traversable": "master",
2624
"purescript-invariant": "master",
2725
"purescript-newtype": "master",
2826
"purescript-prelude": "master"

src/Data/Const.purs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,10 @@ module Data.Const where
22

33
import Prelude
44

5-
import Data.Bifoldable (class Bifoldable)
6-
import Data.Bifunctor (class Bifunctor)
7-
import Data.Bitraversable (class Bitraversable)
85
import Data.Eq (class Eq1)
9-
import Data.Foldable (class Foldable)
10-
import Data.FoldableWithIndex (class FoldableWithIndex)
11-
import Data.Functor.Contravariant (class Contravariant)
126
import Data.Functor.Invariant (class Invariant, imapF)
13-
import Data.FunctorWithIndex (class FunctorWithIndex)
147
import Data.Newtype (class Newtype)
158
import Data.Ord (class Ord1)
16-
import Data.Traversable (class Traversable)
17-
import Data.TraversableWithIndex (class TraversableWithIndex)
189

1910
-- | The `Const` type constructor, which wraps its first type argument
2011
-- | and ignores its second. That is, `Const a b` is isomorphic to `a`
@@ -62,46 +53,11 @@ derive newtype instance booleanAlgebraConst :: BooleanAlgebra a => BooleanAlgebr
6253

6354
derive instance functorConst :: Functor (Const a)
6455

65-
instance bifunctorConst :: Bifunctor Const where
66-
bimap f _ (Const a) = Const (f a)
67-
68-
instance functorWithIndexConst :: FunctorWithIndex Void (Const a) where
69-
mapWithIndex _ (Const x) = Const x
70-
7156
instance invariantConst :: Invariant (Const a) where
7257
imap = imapF
7358

74-
instance contravariantConst :: Contravariant (Const a) where
75-
cmap _ (Const x) = Const x
76-
7759
instance applyConst :: Semigroup a => Apply (Const a) where
7860
apply (Const x) (Const y) = Const (x <> y)
7961

8062
instance applicativeConst :: Monoid a => Applicative (Const a) where
8163
pure _ = Const mempty
82-
83-
instance foldableConst :: Foldable (Const a) where
84-
foldr _ z _ = z
85-
foldl _ z _ = z
86-
foldMap _ _ = mempty
87-
88-
instance foldableWithIndexConst :: FoldableWithIndex Void (Const a) where
89-
foldrWithIndex _ z _ = z
90-
foldlWithIndex _ z _ = z
91-
foldMapWithIndex _ _ = mempty
92-
93-
instance bifoldableConst :: Bifoldable Const where
94-
bifoldr f _ z (Const a) = f a z
95-
bifoldl f _ z (Const a) = f z a
96-
bifoldMap f _ (Const a) = f a
97-
98-
instance traversableConst :: Traversable (Const a) where
99-
traverse _ (Const x) = pure (Const x)
100-
sequence (Const x) = pure (Const x)
101-
102-
instance traversableWithIndexConst :: TraversableWithIndex Void (Const a) where
103-
traverseWithIndex _ (Const x) = pure (Const x)
104-
105-
instance bitraversableConst :: Bitraversable Const where
106-
bitraverse f _ (Const a) = Const <$> f a
107-
bisequence (Const a) = Const <$> a

0 commit comments

Comments
 (0)