Skip to content

Commit b3e64dd

Browse files
Replace polymorphic proxy workaround with monomorphic Proxy type (#281)
* Remove polymorphic proxy workaround This also formats code via purs-tidy * Drop Proxy2 and Proxy3 types & instances * Update changelog
1 parent 2ab0477 commit b3e64dd

15 files changed

+301
-336
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88
- Migrated FFI to ES Modules (#287 by @kl0tl and @JordanMartinez)
99
- Change Generic Rep's `NoConstructors` to newtype `Void` (#282 by @JordanMartinez)
10+
- Replace `forall proxy. proxy k` workaound with `Proxy k` (#281 by @JordanMartinez)
11+
- Drop all kind-specific Proxy types (e.g. `Proxy2`, `Proxy3`) (#281 by @JordanMartinez)
1012

1113
New features:
1214

src/Control/Bind.purs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
module Control.Bind
2-
( class Bind, bind, (>>=)
3-
, bindFlipped, (=<<)
4-
, class Discard, discard
2+
( class Bind
3+
, bind
4+
, (>>=)
5+
, bindFlipped
6+
, (=<<)
7+
, class Discard
8+
, discard
59
, join
6-
, composeKleisli, (>=>)
7-
, composeKleisliFlipped, (<=<)
10+
, composeKleisli
11+
, (>=>)
12+
, composeKleisliFlipped
13+
, (<=<)
814
, ifM
915
, module Data.Functor
1016
, module Control.Apply
@@ -18,7 +24,7 @@ import Control.Category (identity)
1824
import Data.Function (flip)
1925
import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
2026
import Data.Unit (Unit)
21-
import Type.Proxy (Proxy(..), Proxy2, Proxy3)
27+
import Type.Proxy (Proxy(..))
2228

2329
-- | The `Bind` type class extends the [`Apply`](#apply) type class with a
2430
-- | "bind" operation `(>>=)` which composes computations in sequence, using
@@ -107,12 +113,6 @@ instance discardUnit :: Discard Unit where
107113
instance discardProxy :: Discard (Proxy a) where
108114
discard = bind
109115

110-
instance discardProxy2 :: Discard (Proxy2 a) where
111-
discard = bind
112-
113-
instance discardProxy3 :: Discard (Proxy3 a) where
114-
discard = bind
115-
116116
-- | Collapse two applications of a monadic type constructor into one.
117117
join :: forall a m. Bind m => m (m a) -> m a
118118
join m = m >>= identity

src/Data/BooleanAlgebra.purs

+8-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Data.Symbol (class IsSymbol)
99
import Data.Unit (Unit)
1010
import Prim.Row as Row
1111
import Prim.RowList as RL
12-
import Type.Proxy (Proxy, Proxy2, Proxy3)
12+
import Type.Proxy (Proxy)
1313

1414
-- | The `BooleanAlgebra` type class represents types that behave like boolean
1515
-- | values.
@@ -26,8 +26,6 @@ instance booleanAlgebraUnit :: BooleanAlgebra Unit
2626
instance booleanAlgebraFn :: BooleanAlgebra b => BooleanAlgebra (a -> b)
2727
instance booleanAlgebraRecord :: (RL.RowToList row list, BooleanAlgebraRecord list row row) => BooleanAlgebra (Record row)
2828
instance booleanAlgebraProxy :: BooleanAlgebra (Proxy a)
29-
instance booleanAlgebraProxy2 :: BooleanAlgebra (Proxy2 a)
30-
instance booleanAlgebraProxy3 :: BooleanAlgebra (Proxy3 a)
3129

3230
-- | A class for records where all fields have `BooleanAlgebra` instances, used
3331
-- | to implement the `BooleanAlgebra` instance for records.
@@ -36,10 +34,10 @@ class HeytingAlgebraRecord rowlist row subrow <= BooleanAlgebraRecord rowlist ro
3634

3735
instance booleanAlgebraRecordNil :: BooleanAlgebraRecord RL.Nil row ()
3836

39-
instance booleanAlgebraRecordCons
40-
:: ( IsSymbol key
41-
, Row.Cons key focus subrowTail subrow
42-
, BooleanAlgebraRecord rowlistTail row subrowTail
43-
, BooleanAlgebra focus
44-
)
45-
=> BooleanAlgebraRecord (RL.Cons key focus rowlistTail) row subrow
37+
instance booleanAlgebraRecordCons ::
38+
( IsSymbol key
39+
, Row.Cons key focus subrowTail subrow
40+
, BooleanAlgebraRecord rowlistTail row subrowTail
41+
, BooleanAlgebra focus
42+
) =>
43+
BooleanAlgebraRecord (RL.Cons key focus rowlistTail) row subrow

src/Data/Bounded.purs

+28-36
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ module Data.Bounded
33
, bottom
44
, top
55
, module Data.Ord
6-
, class BoundedRecord, bottomRecord, topRecord
6+
, class BoundedRecord
7+
, bottomRecord
8+
, topRecord
79
) where
810

911
import Data.Ord (class Ord, class OrdRecord, Ordering(..), compare, (<), (<=), (>), (>=))
@@ -12,7 +14,7 @@ import Data.Unit (Unit, unit)
1214
import Prim.Row as Row
1315
import Prim.RowList as RL
1416
import Record.Unsafe (unsafeSet)
15-
import Type.Proxy (Proxy(..), Proxy2(..), Proxy3(..))
17+
import Type.Proxy (Proxy(..))
1618

1719
-- | The `Bounded` type class represents totally ordered types that have an
1820
-- | upper and lower boundary.
@@ -65,49 +67,39 @@ instance boundedProxy :: Bounded (Proxy a) where
6567
bottom = Proxy
6668
top = Proxy
6769

68-
instance boundedProxy2 :: Bounded (Proxy2 a) where
69-
bottom = Proxy2
70-
top = Proxy2
71-
72-
instance boundedProxy3 :: Bounded (Proxy3 a) where
73-
bottom = Proxy3
74-
top = Proxy3
75-
7670
class BoundedRecord :: RL.RowList Type -> Row Type -> Row Type -> Constraint
7771
class OrdRecord rowlist row <= BoundedRecord rowlist row subrow | rowlist -> subrow where
78-
topRecord :: forall rlproxy rproxy. rlproxy rowlist -> rproxy row -> Record subrow
79-
bottomRecord :: forall rlproxy rproxy. rlproxy rowlist -> rproxy row -> Record subrow
72+
topRecord :: Proxy rowlist -> Proxy row -> Record subrow
73+
bottomRecord :: Proxy rowlist -> Proxy row -> Record subrow
8074

8175
instance boundedRecordNil :: BoundedRecord RL.Nil row () where
8276
topRecord _ _ = {}
8377
bottomRecord _ _ = {}
8478

85-
instance boundedRecordCons
86-
:: ( IsSymbol key
87-
, Bounded focus
88-
, Row.Cons key focus rowTail row
89-
, Row.Cons key focus subrowTail subrow
90-
, BoundedRecord rowlistTail row subrowTail
91-
)
92-
=> BoundedRecord (RL.Cons key focus rowlistTail) row subrow where
93-
topRecord _ rowProxy
94-
= insert top tail
79+
instance boundedRecordCons ::
80+
( IsSymbol key
81+
, Bounded focus
82+
, Row.Cons key focus rowTail row
83+
, Row.Cons key focus subrowTail subrow
84+
, BoundedRecord rowlistTail row subrowTail
85+
) =>
86+
BoundedRecord (RL.Cons key focus rowlistTail) row subrow where
87+
topRecord _ rowProxy = insert top tail
9588
where
96-
key = reflectSymbol (Proxy :: Proxy key)
97-
insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow
98-
tail = topRecord (Proxy :: Proxy rowlistTail) rowProxy
89+
key = reflectSymbol (Proxy :: Proxy key)
90+
insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow
91+
tail = topRecord (Proxy :: Proxy rowlistTail) rowProxy
9992

100-
bottomRecord _ rowProxy
101-
= insert bottom tail
93+
bottomRecord _ rowProxy = insert bottom tail
10294
where
103-
key = reflectSymbol (Proxy :: Proxy key)
104-
insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow
105-
tail = bottomRecord (Proxy :: Proxy rowlistTail) rowProxy
106-
107-
instance boundedRecord
108-
:: ( RL.RowToList row list
109-
, BoundedRecord list row row
110-
)
111-
=> Bounded (Record row) where
95+
key = reflectSymbol (Proxy :: Proxy key)
96+
insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow
97+
tail = bottomRecord (Proxy :: Proxy rowlistTail) rowProxy
98+
99+
instance boundedRecord ::
100+
( RL.RowToList row list
101+
, BoundedRecord list row row
102+
) =>
103+
Bounded (Record row) where
112104
top = topRecord (Proxy :: Proxy list) (Proxy :: Proxy row)
113105
bottom = bottomRecord (Proxy :: Proxy list) (Proxy :: Proxy row)

src/Data/CommutativeRing.purs

+8-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Data.Symbol (class IsSymbol)
1111
import Data.Unit (Unit)
1212
import Prim.Row as Row
1313
import Prim.RowList as RL
14-
import Type.Proxy (Proxy, Proxy2, Proxy3)
14+
import Type.Proxy (Proxy)
1515

1616
-- | The `CommutativeRing` class is for rings where multiplication is
1717
-- | commutative.
@@ -28,19 +28,17 @@ instance commutativeRingUnit :: CommutativeRing Unit
2828
instance commutativeRingFn :: CommutativeRing b => CommutativeRing (a -> b)
2929
instance commutativeRingRecord :: (RL.RowToList row list, CommutativeRingRecord list row row) => CommutativeRing (Record row)
3030
instance commutativeRingProxy :: CommutativeRing (Proxy a)
31-
instance commutativeRingProxy2 :: CommutativeRing (Proxy2 a)
32-
instance commutativeRingProxy3 :: CommutativeRing (Proxy3 a)
3331

3432
-- | A class for records where all fields have `CommutativeRing` instances, used
3533
-- | to implement the `CommutativeRing` instance for records.
3634
class RingRecord rowlist row subrow <= CommutativeRingRecord rowlist row subrow | rowlist -> subrow
3735

3836
instance commutativeRingRecordNil :: CommutativeRingRecord RL.Nil row ()
3937

40-
instance commutativeRingRecordCons
41-
:: ( IsSymbol key
42-
, Row.Cons key focus subrowTail subrow
43-
, CommutativeRingRecord rowlistTail row subrowTail
44-
, CommutativeRing focus
45-
)
46-
=> CommutativeRingRecord (RL.Cons key focus rowlistTail) row subrow
38+
instance commutativeRingRecordCons ::
39+
( IsSymbol key
40+
, Row.Cons key focus subrowTail subrow
41+
, CommutativeRingRecord rowlistTail row subrowTail
42+
, CommutativeRing focus
43+
) =>
44+
CommutativeRingRecord (RL.Cons key focus rowlistTail) row subrow

src/Data/Eq.purs

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
module Data.Eq
2-
( class Eq, eq, (==), notEq, (/=)
3-
, class Eq1, eq1, notEq1
4-
, class EqRecord, eqRecord
2+
( class Eq
3+
, eq
4+
, (==)
5+
, notEq
6+
, (/=)
7+
, class Eq1
8+
, eq1
9+
, notEq1
10+
, class EqRecord
11+
, eqRecord
512
) where
613

714
import Data.HeytingAlgebra ((&&))
@@ -11,7 +18,7 @@ import Data.Void (Void)
1118
import Prim.Row as Row
1219
import Prim.RowList as RL
1320
import Record.Unsafe (unsafeGet)
14-
import Type.Proxy (Proxy(..), Proxy2, Proxy3)
21+
import Type.Proxy (Proxy(..))
1522

1623
-- | The `Eq` type class represents types which support decidable equality.
1724
-- |
@@ -67,12 +74,6 @@ instance eqRec :: (RL.RowToList row list, EqRecord list row) => Eq (Record row)
6774
instance eqProxy :: Eq (Proxy a) where
6875
eq _ _ = true
6976

70-
instance eqProxy2 :: Eq (Proxy2 a) where
71-
eq _ _ = true
72-
73-
instance eqProxy3 :: Eq (Proxy3 a) where
74-
eq _ _ = true
75-
7677
foreign import eqBooleanImpl :: Boolean -> Boolean -> Boolean
7778
foreign import eqIntImpl :: Int -> Int -> Boolean
7879
foreign import eqNumberImpl :: Number -> Number -> Boolean
@@ -95,20 +96,20 @@ notEq1 x y = (x `eq1` y) == false
9596
-- | the `Eq` instance for records.
9697
class EqRecord :: RL.RowList Type -> Row Type -> Constraint
9798
class EqRecord rowlist row where
98-
eqRecord :: forall rlproxy. rlproxy rowlist -> Record row -> Record row -> Boolean
99+
eqRecord :: Proxy rowlist -> Record row -> Record row -> Boolean
99100

100101
instance eqRowNil :: EqRecord RL.Nil row where
101102
eqRecord _ _ _ = true
102103

103-
instance eqRowCons
104-
:: ( EqRecord rowlistTail row
105-
, Row.Cons key focus rowTail row
106-
, IsSymbol key
107-
, Eq focus
108-
)
109-
=> EqRecord (RL.Cons key focus rowlistTail) row where
104+
instance eqRowCons ::
105+
( EqRecord rowlistTail row
106+
, Row.Cons key focus rowTail row
107+
, IsSymbol key
108+
, Eq focus
109+
) =>
110+
EqRecord (RL.Cons key focus rowlistTail) row where
110111
eqRecord _ ra rb = (get ra == get rb) && tail
111112
where
112-
key = reflectSymbol (Proxy :: Proxy key)
113-
get = unsafeGet key :: Record row -> focus
114-
tail = eqRecord (Proxy :: Proxy rowlistTail) ra rb
113+
key = reflectSymbol (Proxy :: Proxy key)
114+
get = unsafeGet key :: Record row -> focus
115+
tail = eqRecord (Proxy :: Proxy rowlistTail) ra rb

0 commit comments

Comments
 (0)