Skip to content

Commit a4a2eba

Browse files
Port Proxy's type class instances into respective type class modules
1 parent 1100459 commit a4a2eba

16 files changed

+143
-144
lines changed

src/Control/Applicative.purs

Lines changed: 4 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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,6 +25,9 @@ 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.

src/Data/Bounded.purs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Prim.RowList as RL
1414
import Record.Unsafe (unsafeSet)
1515
import Type.Data.Row (RProxy(..))
1616
import Type.Data.RowList (RLProxy(..))
17+
import Type.Proxy (Proxy(..), Proxy2(..), Proxy3(..))
1718

1819
-- | The `Bounded` type class represents totally ordered types that have an
1920
-- | upper and lower boundary.
@@ -62,6 +63,18 @@ instance boundedNumber :: Bounded Number where
6263
top = topNumber
6364
bottom = bottomNumber
6465

66+
instance boundedProxy :: Bounded (Proxy a) where
67+
bottom = Proxy
68+
top = Proxy
69+
70+
instance boundedProxy2 :: Bounded (Proxy2 a) where
71+
bottom = Proxy2
72+
top = Proxy2
73+
74+
instance boundedProxy3 :: Bounded (Proxy3 a) where
75+
bottom = Proxy3
76+
top = Proxy3
77+
6578
class OrdRecord rowlist row <= BoundedRecord rowlist row subrow | rowlist -> subrow where
6679
topRecord :: RLProxy rowlist -> RProxy row -> Record subrow
6780
bottomRecord :: RLProxy rowlist -> RProxy row -> Record subrow

src/Data/CommutativeRing.purs

Lines changed: 4 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Prim.Row as Row
1212
import Prim.RowList as RL
1313
import Record.Unsafe (unsafeGet)
1414
import Type.Data.RowList (RLProxy(..))
15+
import Type.Proxy (Proxy, Proxy2, Proxy3)
1516

1617
-- | The `Eq` type class represents types which support decidable equality.
1718
-- |
@@ -64,6 +65,15 @@ instance eqArray :: Eq a => Eq (Array a) where
6465
instance eqRec :: (RL.RowToList row list, EqRecord list row) => Eq (Record row) where
6566
eq = eqRecord (RLProxy :: RLProxy list)
6667

68+
instance eqProxy :: Eq (Proxy a) where
69+
eq _ _ = true
70+
71+
instance eqProxy2 :: Eq (Proxy2 a) where
72+
eq _ _ = true
73+
74+
instance eqProxy3 :: Eq (Proxy3 a) where
75+
eq _ _ = true
76+
6777
foreign import eqBooleanImpl :: Boolean -> Boolean -> Boolean
6878
foreign import eqIntImpl :: Int -> Int -> Boolean
6979
foreign import eqNumberImpl :: Number -> Number -> Boolean

src/Data/Functor.purs

Lines changed: 4 additions & 0 deletions
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

src/Data/HeytingAlgebra.purs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Prim.RowList as RL
1010
import Record.Unsafe (unsafeGet, unsafeSet)
1111
import Type.Data.Row (RProxy(..))
1212
import Type.Data.RowList (RLProxy(..))
13+
import Type.Proxy (Proxy(..), Proxy2(..), Proxy3(..))
1314

1415
-- | The `HeytingAlgebra` type class represents types that are bounded lattices with
1516
-- | an implication operator such that the following laws hold:
@@ -71,6 +72,30 @@ instance heytingAlgebraFunction :: HeytingAlgebra b => HeytingAlgebra (a -> b) w
7172
disj f g a = f a || g a
7273
not f a = not (f a)
7374

75+
instance heytingAlgebraProxy :: HeytingAlgebra (Proxy a) where
76+
conj _ _ = Proxy
77+
disj _ _ = Proxy
78+
implies _ _ = Proxy
79+
ff = Proxy
80+
not _ = Proxy
81+
tt = Proxy
82+
83+
instance heytingAlgebraProxy2 :: HeytingAlgebra (Proxy2 a) where
84+
conj _ _ = Proxy2
85+
disj _ _ = Proxy2
86+
implies _ _ = Proxy2
87+
ff = Proxy2
88+
not _ = Proxy2
89+
tt = Proxy2
90+
91+
instance heytingAlgebraProxy3 :: HeytingAlgebra (Proxy3 a) where
92+
conj _ _ = Proxy3
93+
disj _ _ = Proxy3
94+
implies _ _ = Proxy3
95+
ff = Proxy3
96+
not _ = Proxy3
97+
tt = Proxy3
98+
7499
instance heytingAlgebraRecord :: (RL.RowToList row list, HeytingAlgebraRecord list row row) => HeytingAlgebra (Record row) where
75100
ff = ffRecord (RLProxy :: RLProxy list) (RProxy :: RProxy row)
76101
tt = ttRecord (RLProxy :: RLProxy list) (RProxy :: RProxy row)

0 commit comments

Comments
 (0)