Skip to content

Replace polymorphic proxy workaround with monomorphic Proxy type #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Notable changes to this project are documented in this file. The format is based
Breaking changes:
- Migrated FFI to ES Modules (#287 by @kl0tl and @JordanMartinez)
- Change Generic Rep's `NoConstructors` to newtype `Void` (#282 by @JordanMartinez)
- Replace `forall proxy. proxy k` workaound with `Proxy k` (#281 by @JordanMartinez)
- Drop all kind-specific Proxy types (e.g. `Proxy2`, `Proxy3`) (#281 by @JordanMartinez)

New features:

Expand Down
24 changes: 12 additions & 12 deletions src/Control/Bind.purs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
module Control.Bind
( class Bind, bind, (>>=)
, bindFlipped, (=<<)
, class Discard, discard
( class Bind
, bind
, (>>=)
, bindFlipped
, (=<<)
, class Discard
, discard
, join
, composeKleisli, (>=>)
, composeKleisliFlipped, (<=<)
, composeKleisli
, (>=>)
, composeKleisliFlipped
, (<=<)
, ifM
, module Data.Functor
, module Control.Apply
Expand All @@ -18,7 +24,7 @@ import Control.Category (identity)
import Data.Function (flip)
import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
import Data.Unit (Unit)
import Type.Proxy (Proxy(..), Proxy2, Proxy3)
import Type.Proxy (Proxy(..))

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

instance discardProxy2 :: Discard (Proxy2 a) where
discard = bind

instance discardProxy3 :: Discard (Proxy3 a) where
discard = bind

-- | Collapse two applications of a monadic type constructor into one.
join :: forall a m. Bind m => m (m a) -> m a
join m = m >>= identity
Expand Down
18 changes: 8 additions & 10 deletions src/Data/BooleanAlgebra.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Data.Symbol (class IsSymbol)
import Data.Unit (Unit)
import Prim.Row as Row
import Prim.RowList as RL
import Type.Proxy (Proxy, Proxy2, Proxy3)
import Type.Proxy (Proxy)

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

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

instance booleanAlgebraRecordNil :: BooleanAlgebraRecord RL.Nil row ()

instance booleanAlgebraRecordCons
:: ( IsSymbol key
, Row.Cons key focus subrowTail subrow
, BooleanAlgebraRecord rowlistTail row subrowTail
, BooleanAlgebra focus
)
=> BooleanAlgebraRecord (RL.Cons key focus rowlistTail) row subrow
instance booleanAlgebraRecordCons ::
( IsSymbol key
, Row.Cons key focus subrowTail subrow
, BooleanAlgebraRecord rowlistTail row subrowTail
, BooleanAlgebra focus
) =>
BooleanAlgebraRecord (RL.Cons key focus rowlistTail) row subrow
64 changes: 28 additions & 36 deletions src/Data/Bounded.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module Data.Bounded
, bottom
, top
, module Data.Ord
, class BoundedRecord, bottomRecord, topRecord
, class BoundedRecord
, bottomRecord
, topRecord
) where

import Data.Ord (class Ord, class OrdRecord, Ordering(..), compare, (<), (<=), (>), (>=))
Expand All @@ -12,7 +14,7 @@ import Data.Unit (Unit, unit)
import Prim.Row as Row
import Prim.RowList as RL
import Record.Unsafe (unsafeSet)
import Type.Proxy (Proxy(..), Proxy2(..), Proxy3(..))
import Type.Proxy (Proxy(..))

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

instance boundedProxy2 :: Bounded (Proxy2 a) where
bottom = Proxy2
top = Proxy2

instance boundedProxy3 :: Bounded (Proxy3 a) where
bottom = Proxy3
top = Proxy3

class BoundedRecord :: RL.RowList Type -> Row Type -> Row Type -> Constraint
class OrdRecord rowlist row <= BoundedRecord rowlist row subrow | rowlist -> subrow where
topRecord :: forall rlproxy rproxy. rlproxy rowlist -> rproxy row -> Record subrow
bottomRecord :: forall rlproxy rproxy. rlproxy rowlist -> rproxy row -> Record subrow
topRecord :: Proxy rowlist -> Proxy row -> Record subrow
bottomRecord :: Proxy rowlist -> Proxy row -> Record subrow

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

instance boundedRecordCons
:: ( IsSymbol key
, Bounded focus
, Row.Cons key focus rowTail row
, Row.Cons key focus subrowTail subrow
, BoundedRecord rowlistTail row subrowTail
)
=> BoundedRecord (RL.Cons key focus rowlistTail) row subrow where
topRecord _ rowProxy
= insert top tail
instance boundedRecordCons ::
( IsSymbol key
, Bounded focus
, Row.Cons key focus rowTail row
, Row.Cons key focus subrowTail subrow
, BoundedRecord rowlistTail row subrowTail
) =>
BoundedRecord (RL.Cons key focus rowlistTail) row subrow where
topRecord _ rowProxy = insert top tail
where
key = reflectSymbol (Proxy :: Proxy key)
insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow
tail = topRecord (Proxy :: Proxy rowlistTail) rowProxy
key = reflectSymbol (Proxy :: Proxy key)
insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow
tail = topRecord (Proxy :: Proxy rowlistTail) rowProxy

bottomRecord _ rowProxy
= insert bottom tail
bottomRecord _ rowProxy = insert bottom tail
where
key = reflectSymbol (Proxy :: Proxy key)
insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow
tail = bottomRecord (Proxy :: Proxy rowlistTail) rowProxy

instance boundedRecord
:: ( RL.RowToList row list
, BoundedRecord list row row
)
=> Bounded (Record row) where
key = reflectSymbol (Proxy :: Proxy key)
insert = unsafeSet key :: focus -> Record subrowTail -> Record subrow
tail = bottomRecord (Proxy :: Proxy rowlistTail) rowProxy

instance boundedRecord ::
( RL.RowToList row list
, BoundedRecord list row row
) =>
Bounded (Record row) where
top = topRecord (Proxy :: Proxy list) (Proxy :: Proxy row)
bottom = bottomRecord (Proxy :: Proxy list) (Proxy :: Proxy row)
18 changes: 8 additions & 10 deletions src/Data/CommutativeRing.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Data.Symbol (class IsSymbol)
import Data.Unit (Unit)
import Prim.Row as Row
import Prim.RowList as RL
import Type.Proxy (Proxy, Proxy2, Proxy3)
import Type.Proxy (Proxy)

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

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

instance commutativeRingRecordNil :: CommutativeRingRecord RL.Nil row ()

instance commutativeRingRecordCons
:: ( IsSymbol key
, Row.Cons key focus subrowTail subrow
, CommutativeRingRecord rowlistTail row subrowTail
, CommutativeRing focus
)
=> CommutativeRingRecord (RL.Cons key focus rowlistTail) row subrow
instance commutativeRingRecordCons ::
( IsSymbol key
, Row.Cons key focus subrowTail subrow
, CommutativeRingRecord rowlistTail row subrowTail
, CommutativeRing focus
) =>
CommutativeRingRecord (RL.Cons key focus rowlistTail) row subrow
43 changes: 22 additions & 21 deletions src/Data/Eq.purs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
module Data.Eq
( class Eq, eq, (==), notEq, (/=)
, class Eq1, eq1, notEq1
, class EqRecord, eqRecord
( class Eq
, eq
, (==)
, notEq
, (/=)
, class Eq1
, eq1
, notEq1
, class EqRecord
, eqRecord
) where

import Data.HeytingAlgebra ((&&))
Expand All @@ -11,7 +18,7 @@ import Data.Void (Void)
import Prim.Row as Row
import Prim.RowList as RL
import Record.Unsafe (unsafeGet)
import Type.Proxy (Proxy(..), Proxy2, Proxy3)
import Type.Proxy (Proxy(..))

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

instance eqProxy2 :: Eq (Proxy2 a) where
eq _ _ = true

instance eqProxy3 :: Eq (Proxy3 a) where
eq _ _ = true

foreign import eqBooleanImpl :: Boolean -> Boolean -> Boolean
foreign import eqIntImpl :: Int -> Int -> Boolean
foreign import eqNumberImpl :: Number -> Number -> Boolean
Expand All @@ -95,20 +96,20 @@ notEq1 x y = (x `eq1` y) == false
-- | the `Eq` instance for records.
class EqRecord :: RL.RowList Type -> Row Type -> Constraint
class EqRecord rowlist row where
eqRecord :: forall rlproxy. rlproxy rowlist -> Record row -> Record row -> Boolean
eqRecord :: Proxy rowlist -> Record row -> Record row -> Boolean

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

instance eqRowCons
:: ( EqRecord rowlistTail row
, Row.Cons key focus rowTail row
, IsSymbol key
, Eq focus
)
=> EqRecord (RL.Cons key focus rowlistTail) row where
instance eqRowCons ::
( EqRecord rowlistTail row
, Row.Cons key focus rowTail row
, IsSymbol key
, Eq focus
) =>
EqRecord (RL.Cons key focus rowlistTail) row where
eqRecord _ ra rb = (get ra == get rb) && tail
where
key = reflectSymbol (Proxy :: Proxy key)
get = unsafeGet key :: Record row -> focus
tail = eqRecord (Proxy :: Proxy rowlistTail) ra rb
key = reflectSymbol (Proxy :: Proxy key)
get = unsafeGet key :: Record row -> focus
tail = eqRecord (Proxy :: Proxy rowlistTail) ra rb
Loading