Skip to content

Commit 212e486

Browse files
authored
Merge pull request #230 from purescript/addProxy
Ports `purescript-proxy` into this repo
2 parents 677d671 + fa7d8d2 commit 212e486

20 files changed

+322
-106
lines changed

src/Control/Applicative.purs

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Control.Apply (class Apply, apply, (*>), (<*), (<*>))
1010

1111
import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
1212
import Data.Unit (Unit, unit)
13+
import Type.Proxy (Proxy(..))
1314

1415
-- | The `Applicative` type class extends the [`Apply`](#apply) type class
1516
-- | with a `pure` function, which can be used to create values of type `f a`
@@ -38,6 +39,9 @@ instance applicativeFn :: Applicative ((->) r) where
3839
instance applicativeArray :: Applicative Array where
3940
pure x = [x]
4041

42+
instance applicativeProxy :: Applicative Proxy where
43+
pure _ = Proxy
44+
4145
-- | `liftA1` provides a default implementation of `(<$>)` for any
4246
-- | [`Applicative`](#applicative) functor, without using `(<$>)` as provided
4347
-- | by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass

src/Control/Apply.purs

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Control.Apply
99
import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
1010
import Data.Function (const)
1111
import Control.Category (identity)
12+
import Type.Proxy (Proxy(..))
1213

1314
-- | The `Apply` class provides the `(<*>)` which is used to apply a function
1415
-- | to an argument under a type constructor.
@@ -54,6 +55,9 @@ instance applyArray :: Apply Array where
5455

5556
foreign import arrayApply :: forall a b. Array (a -> b) -> Array a -> Array b
5657

58+
instance applyProxy :: Apply Proxy where
59+
apply _ _ = Proxy
60+
5761
-- | Combine two effectful actions, keeping only the result of the first.
5862
applyFirst :: forall a b f. Apply f => f a -> f b -> f a
5963
applyFirst a b = const <$> a <*> b

src/Control/Bind.purs

+13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Control.Category (identity)
1919
import Data.Function (flip)
2020
import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
2121
import Data.Unit (Unit)
22+
import Type.Proxy (Proxy(..), Proxy2, Proxy3)
2223

2324
-- | The `Bind` type class extends the [`Apply`](#apply) type class with a
2425
-- | "bind" operation `(>>=)` which composes computations in sequence, using
@@ -90,6 +91,9 @@ instance bindArray :: Bind Array where
9091

9192
foreign import arrayBind :: forall a b. Array a -> (a -> Array b) -> Array b
9293

94+
instance bindProxy :: Bind Proxy where
95+
bind _ _ = Proxy
96+
9397
-- | A class for types whose values can safely be discarded
9498
-- | in a `do` notation block.
9599
-- |
@@ -101,6 +105,15 @@ class Discard a where
101105
instance discardUnit :: Discard Unit where
102106
discard = bind
103107

108+
instance discardProxy :: Discard (Proxy a) where
109+
discard = bind
110+
111+
instance discardProxy2 :: Discard (Proxy2 a) where
112+
discard = bind
113+
114+
instance discardProxy3 :: Discard (Proxy3 a) where
115+
discard = bind
116+
104117
-- | Collapse two applications of a monadic type constructor into one.
105118
join :: forall a m. Bind m => m (m a) -> m a
106119
join m = m >>= identity

src/Control/Monad.purs

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Control.Bind (class Bind, bind, ap, ifM, join, (<=<), (=<<), (>=>), (>>=)
1515

1616
import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
1717
import Data.Unit (Unit)
18+
import Type.Proxy (Proxy)
1819

1920
-- | The `Monad` type class combines the operations of the `Bind` and
2021
-- | `Applicative` type classes. Therefore, `Monad` instances represent type
@@ -32,6 +33,8 @@ instance monadFn :: Monad ((->) r)
3233

3334
instance monadArray :: Monad Array
3435

36+
instance monadProxy :: Monad Proxy
37+
3538
-- | `liftM1` provides a default implementation of `(<$>)` for any
3639
-- | [`Monad`](#monad), without using `(<$>)` as provided by the
3740
-- | [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.

src/Data/BooleanAlgebra.purs

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +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)
1213

1314
-- | The `BooleanAlgebra` type class represents types that behave like boolean
1415
-- | values.
@@ -24,9 +25,13 @@ instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
2425
instance booleanAlgebraUnit :: BooleanAlgebra Unit
2526
instance booleanAlgebraFn :: BooleanAlgebra b => BooleanAlgebra (a -> b)
2627
instance booleanAlgebraRecord :: (RL.RowToList row list, BooleanAlgebraRecord list row row) => BooleanAlgebra (Record row)
28+
instance booleanAlgebraProxy :: BooleanAlgebra (Proxy a)
29+
instance booleanAlgebraProxy2 :: BooleanAlgebra (Proxy2 a)
30+
instance booleanAlgebraProxy3 :: BooleanAlgebra (Proxy3 a)
2731

2832
-- | A class for records where all fields have `BooleanAlgebra` instances, used
2933
-- | to implement the `BooleanAlgebra` instance for records.
34+
class BooleanAlgebraRecord :: RL.RowList Type -> Row Type -> Row Type -> Constraint
3035
class HeytingAlgebraRecord rowlist row subrow <= BooleanAlgebraRecord rowlist row subrow | rowlist -> subrow
3136

3237
instance booleanAlgebraRecordNil :: BooleanAlgebraRecord RL.Nil row ()

src/Data/Bounded.purs

+23-11
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ module Data.Bounded
77
) where
88

99
import Data.Ord (class Ord, class OrdRecord, Ordering(..), compare, (<), (<=), (>), (>=))
10-
import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
10+
import Data.Symbol (class IsSymbol, reflectSymbol)
1111
import Data.Unit (Unit, unit)
1212
import Prim.Row as Row
1313
import Prim.RowList as RL
1414
import Record.Unsafe (unsafeSet)
15-
import Type.Data.Row (RProxy(..))
16-
import Type.Data.RowList (RLProxy(..))
15+
import Type.Proxy (Proxy(..), Proxy2(..), Proxy3(..))
1716

1817
-- | The `Bounded` type class represents totally ordered types that have an
1918
-- | upper and lower boundary.
@@ -62,9 +61,22 @@ instance boundedNumber :: Bounded Number where
6261
top = topNumber
6362
bottom = bottomNumber
6463

64+
instance boundedProxy :: Bounded (Proxy a) where
65+
bottom = Proxy
66+
top = Proxy
67+
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+
76+
class BoundedRecord :: RL.RowList Type -> Row Type -> Row Type -> Constraint
6577
class OrdRecord rowlist row <= BoundedRecord rowlist row subrow | rowlist -> subrow where
66-
topRecord :: RLProxy rowlist -> RProxy row -> Record subrow
67-
bottomRecord :: RLProxy rowlist -> RProxy row -> Record subrow
78+
topRecord :: forall rlproxy rproxy. rlproxy rowlist -> rproxy row -> Record subrow
79+
bottomRecord :: forall rlproxy rproxy. rlproxy rowlist -> rproxy row -> Record subrow
6880

6981
instance boundedRecordNil :: BoundedRecord RL.Nil row () where
7082
topRecord _ _ = {}
@@ -81,21 +93,21 @@ instance boundedRecordCons
8193
topRecord _ rowProxy
8294
= insert top tail
8395
where
84-
key = reflectSymbol (SProxy :: SProxy key)
96+
key = reflectSymbol (Proxy :: Proxy key)
8597
insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow
86-
tail = topRecord (RLProxy :: RLProxy rowlistTail) rowProxy
98+
tail = topRecord (Proxy :: Proxy rowlistTail) rowProxy
8799

88100
bottomRecord _ rowProxy
89101
= insert bottom tail
90102
where
91-
key = reflectSymbol (SProxy :: SProxy key)
103+
key = reflectSymbol (Proxy :: Proxy key)
92104
insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow
93-
tail = bottomRecord (RLProxy :: RLProxy rowlistTail) rowProxy
105+
tail = bottomRecord (Proxy :: Proxy rowlistTail) rowProxy
94106

95107
instance boundedRecord
96108
:: ( RL.RowToList row list
97109
, BoundedRecord list row row
98110
)
99111
=> Bounded (Record row) where
100-
top = topRecord (RLProxy :: RLProxy list) (RProxy :: RProxy row)
101-
bottom = bottomRecord (RLProxy :: RLProxy list) (RProxy :: RProxy row)
112+
top = topRecord (Proxy :: Proxy list) (Proxy :: Proxy row)
113+
bottom = bottomRecord (Proxy :: Proxy list) (Proxy :: Proxy row)

src/Data/CommutativeRing.purs

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +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)
1415

1516
-- | The `CommutativeRing` class is for rings where multiplication is
1617
-- | commutative.
@@ -26,6 +27,9 @@ instance commutativeRingNumber :: CommutativeRing Number
2627
instance commutativeRingUnit :: CommutativeRing Unit
2728
instance commutativeRingFn :: CommutativeRing b => CommutativeRing (a -> b)
2829
instance commutativeRingRecord :: (RL.RowToList row list, CommutativeRingRecord list row row) => CommutativeRing (Record row)
30+
instance commutativeRingProxy :: CommutativeRing (Proxy a)
31+
instance commutativeRingProxy2 :: CommutativeRing (Proxy2 a)
32+
instance commutativeRingProxy3 :: CommutativeRing (Proxy3 a)
2933

3034
-- | A class for records where all fields have `CommutativeRing` instances, used
3135
-- | to implement the `CommutativeRing` instance for records.

src/Data/Eq.purs

+16-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ module Data.Eq
55
) where
66

77
import Data.HeytingAlgebra ((&&))
8-
import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
8+
import Data.Symbol (class IsSymbol, reflectSymbol)
99
import Data.Unit (Unit)
1010
import Data.Void (Void)
1111
import Prim.Row as Row
1212
import Prim.RowList as RL
1313
import Record.Unsafe (unsafeGet)
14-
import Type.Data.RowList (RLProxy(..))
14+
import Type.Proxy (Proxy(..), Proxy2, Proxy3)
1515

1616
-- | The `Eq` type class represents types which support decidable equality.
1717
-- |
@@ -62,7 +62,16 @@ instance eqArray :: Eq a => Eq (Array a) where
6262
eq = eqArrayImpl eq
6363

6464
instance eqRec :: (RL.RowToList row list, EqRecord list row) => Eq (Record row) where
65-
eq = eqRecord (RLProxy :: RLProxy list)
65+
eq = eqRecord (Proxy :: Proxy list)
66+
67+
instance eqProxy :: Eq (Proxy a) where
68+
eq _ _ = true
69+
70+
instance eqProxy2 :: Eq (Proxy2 a) where
71+
eq _ _ = true
72+
73+
instance eqProxy3 :: Eq (Proxy3 a) where
74+
eq _ _ = true
6675

6776
foreign import eqBooleanImpl :: Boolean -> Boolean -> Boolean
6877
foreign import eqIntImpl :: Int -> Int -> Boolean
@@ -84,8 +93,9 @@ notEq1 x y = (x `eq1` y) == false
8493

8594
-- | A class for records where all fields have `Eq` instances, used to implement
8695
-- | the `Eq` instance for records.
96+
class EqRecord :: RL.RowList Type -> Row Type -> Constraint
8797
class EqRecord rowlist row where
88-
eqRecord :: RLProxy rowlist -> Record row -> Record row -> Boolean
98+
eqRecord :: forall rlproxy. rlproxy rowlist -> Record row -> Record row -> Boolean
8999

90100
instance eqRowNil :: EqRecord RL.Nil row where
91101
eqRecord _ _ _ = true
@@ -99,6 +109,6 @@ instance eqRowCons
99109
=> EqRecord (RL.Cons key focus rowlistTail) row where
100110
eqRecord _ ra rb = (get ra == get rb) && tail
101111
where
102-
key = reflectSymbol (SProxy :: SProxy key)
112+
key = reflectSymbol (Proxy :: Proxy key)
103113
get = unsafeGet key :: Record row -> focus
104-
tail = eqRecord (RLProxy :: RLProxy rowlistTail) ra rb
114+
tail = eqRecord (Proxy :: Proxy rowlistTail) ra rb

src/Data/Functor.purs

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Data.Functor
99

1010
import Data.Function (const, compose)
1111
import Data.Unit (Unit, unit)
12+
import Type.Proxy (Proxy(..))
1213

1314
-- | A `Functor` is a type constructor which supports a mapping operation
1415
-- | `map`.
@@ -42,6 +43,9 @@ instance functorFn :: Functor ((->) r) where
4243
instance functorArray :: Functor Array where
4344
map = arrayMap
4445

46+
instance functorProxy :: Functor Proxy where
47+
map _ _ = Proxy
48+
4549
foreign import arrayMap :: forall a b. (a -> b) -> Array a -> Array b
4650

4751
-- | The `void` function is used to ignore the type wrapped by a

0 commit comments

Comments
 (0)