Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
4 changes: 4 additions & 0 deletions src/Control/Applicative.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Control.Apply (class Apply, apply, (*>), (<*), (<*>))

import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
import Data.Unit (Unit, unit)
import Type.Proxy (Proxy(..))

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

instance applicativeProxy :: Applicative Proxy where
pure _ = Proxy

-- | `liftA1` provides a default implementation of `(<$>)` for any
-- | [`Applicative`](#applicative) functor, without using `(<$>)` as provided
-- | by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass
Expand Down
4 changes: 4 additions & 0 deletions src/Control/Apply.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Control.Apply
import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
import Data.Function (const)
import Control.Category (identity)
import Type.Proxy (Proxy(..))

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

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

instance applyProxy :: Apply Proxy where
apply _ _ = Proxy

-- | Combine two effectful actions, keeping only the result of the first.
applyFirst :: forall a b f. Apply f => f a -> f b -> f a
applyFirst a b = const <$> a <*> b
Expand Down
13 changes: 13 additions & 0 deletions src/Control/Bind.purs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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)

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

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

instance bindProxy :: Bind Proxy where
bind _ _ = Proxy

-- | A class for types whose values can safely be discarded
-- | in a `do` notation block.
-- |
Expand All @@ -101,6 +105,15 @@ class Discard a where
instance discardUnit :: Discard Unit where
discard = bind

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
3 changes: 3 additions & 0 deletions src/Control/Monad.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Control.Bind (class Bind, bind, ap, ifM, join, (<=<), (=<<), (>=>), (>>=)

import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
import Data.Unit (Unit)
import Type.Proxy (Proxy)

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

instance monadArray :: Monad Array

instance monadProxy :: Monad Proxy

-- | `liftM1` provides a default implementation of `(<$>)` for any
-- | [`Monad`](#monad), without using `(<$>)` as provided by the
-- | [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
Expand Down
4 changes: 4 additions & 0 deletions src/Data/BooleanAlgebra.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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)

-- | The `BooleanAlgebra` type class represents types that behave like boolean
-- | values.
Expand All @@ -24,6 +25,9 @@ instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
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 Down
13 changes: 13 additions & 0 deletions src/Data/Bounded.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Prim.RowList as RL
import Record.Unsafe (unsafeSet)
import Type.Data.Row (RProxy(..))
import Type.Data.RowList (RLProxy(..))
import Type.Proxy (Proxy(..), Proxy2(..), Proxy3(..))

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

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 OrdRecord rowlist row <= BoundedRecord rowlist row subrow | rowlist -> subrow where
topRecord :: RLProxy rowlist -> RProxy row -> Record subrow
bottomRecord :: RLProxy rowlist -> RProxy row -> Record subrow
Expand Down
4 changes: 4 additions & 0 deletions src/Data/CommutativeRing.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +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)

-- | The `CommutativeRing` class is for rings where multiplication is
-- | commutative.
Expand All @@ -26,6 +27,9 @@ instance commutativeRingNumber :: CommutativeRing Number
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.
Expand Down
10 changes: 10 additions & 0 deletions src/Data/Eq.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Prim.Row as Row
import Prim.RowList as RL
import Record.Unsafe (unsafeGet)
import Type.Data.RowList (RLProxy(..))
import Type.Proxy (Proxy, Proxy2, Proxy3)

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

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 Down
4 changes: 4 additions & 0 deletions src/Data/Functor.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Data.Functor

import Data.Function (const, compose)
import Data.Unit (Unit, unit)
import Type.Proxy (Proxy(..))

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

instance functorProxy :: Functor Proxy where
map _ _ = Proxy

foreign import arrayMap :: forall a b. (a -> b) -> Array a -> Array b

-- | The `void` function is used to ignore the type wrapped by a
Expand Down
25 changes: 25 additions & 0 deletions src/Data/HeytingAlgebra.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Prim.RowList as RL
import Record.Unsafe (unsafeGet, unsafeSet)
import Type.Data.Row (RProxy(..))
import Type.Data.RowList (RLProxy(..))
import Type.Proxy (Proxy(..), Proxy2(..), Proxy3(..))

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

instance heytingAlgebraProxy :: HeytingAlgebra (Proxy a) where
conj _ _ = Proxy
disj _ _ = Proxy
implies _ _ = Proxy
ff = Proxy
not _ = Proxy
tt = Proxy

instance heytingAlgebraProxy2 :: HeytingAlgebra (Proxy2 a) where
conj _ _ = Proxy2
disj _ _ = Proxy2
implies _ _ = Proxy2
ff = Proxy2
not _ = Proxy2
tt = Proxy2

instance heytingAlgebraProxy3 :: HeytingAlgebra (Proxy3 a) where
conj _ _ = Proxy3
disj _ _ = Proxy3
implies _ _ = Proxy3
ff = Proxy3
not _ = Proxy3
tt = Proxy3

instance heytingAlgebraRecord :: (RL.RowToList row list, HeytingAlgebraRecord list row row) => HeytingAlgebra (Record row) where
ff = ffRecord (RLProxy :: RLProxy list) (RProxy :: RProxy row)
tt = ttRecord (RLProxy :: RLProxy list) (RProxy :: RProxy row)
Expand Down
11 changes: 10 additions & 1 deletion src/Data/Ord.purs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Prim.Row as Row
import Prim.RowList as RL
import Record.Unsafe (unsafeGet)
import Type.Data.RowList (RLProxy(..))
import Type.Proxy (Proxy, Proxy2, Proxy3)

-- | The `Ord` type class represents types which support comparisons with a
-- | _total order_.
Expand Down Expand Up @@ -58,6 +59,15 @@ instance ordUnit :: Ord Unit where
instance ordVoid :: Ord Void where
compare _ _ = EQ

instance ordProxy :: Ord (Proxy a) where
compare _ _ = EQ

instance ordProxy2 :: Ord (Proxy2 a) where
compare _ _ = EQ

instance ordProxy3 :: Ord (Proxy3 a) where
compare _ _ = EQ

instance ordArray :: Ord a => Ord (Array a) where
compare = \xs ys -> compare 0 (ordArrayImpl toDelta xs ys)
where
Expand Down Expand Up @@ -242,4 +252,3 @@ instance ordRecord
)
=> Ord (Record row) where
compare = compareRecord (RLProxy :: RLProxy list)

10 changes: 10 additions & 0 deletions src/Data/Ring.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Prim.Row as Row
import Prim.RowList as RL
import Record.Unsafe (unsafeGet, unsafeSet)
import Type.Data.RowList (RLProxy(..))
import Type.Proxy (Proxy(..), Proxy2(..), Proxy3(..))

-- | The `Ring` class is for types that support addition, multiplication,
-- | and subtraction operations.
Expand All @@ -36,6 +37,15 @@ instance ringUnit :: Ring Unit where
instance ringFn :: Ring b => Ring (a -> b) where
sub f g x = f x - g x

instance ringProxy :: Ring (Proxy a) where
sub _ _ = Proxy

instance ringProxy2 :: Ring (Proxy2 a) where
sub _ _ = Proxy2

instance ringProxy3 :: Ring (Proxy3 a) where
sub _ _ = Proxy3

instance ringRecord :: (RL.RowToList row list, RingRecord list row row) => Ring (Record row) where
sub = subRecord (RLProxy :: RLProxy list)

Expand Down
10 changes: 10 additions & 0 deletions src/Data/Semigroup.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Prim.Row as Row
import Prim.RowList as RL
import Record.Unsafe (unsafeGet, unsafeSet)
import Type.Data.RowList (RLProxy(..))
import Type.Proxy (Proxy(..), Proxy2(..), Proxy3(..))

-- | The `Semigroup` type class identifies an associative operation on a type.
-- |
Expand Down Expand Up @@ -48,6 +49,15 @@ instance semigroupFn :: Semigroup s' => Semigroup (s -> s') where
instance semigroupArray :: Semigroup (Array a) where
append = concatArray

instance semigroupProxy :: Semigroup (Proxy a) where
append _ _ = Proxy

instance semigroupProxy2 :: Semigroup (Proxy2 a) where
append _ _ = Proxy2

instance semigroupProxy3 :: Semigroup (Proxy3 a) where
append _ _ = Proxy3

instance semigroupRecord :: (RL.RowToList row list, SemigroupRecord list row row) => Semigroup (Record row) where
append = appendRecord (RLProxy :: RLProxy list)

Expand Down
19 changes: 19 additions & 0 deletions src/Data/Semiring.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Prim.RowList as RL
import Record.Unsafe (unsafeGet, unsafeSet)
import Type.Data.Row (RProxy(..))
import Type.Data.RowList (RLProxy(..))
import Type.Proxy (Proxy(..), Proxy2(..), Proxy3(..))

-- | The `Semiring` class is for types that support an addition and
-- | multiplication operation.
Expand Down Expand Up @@ -65,6 +66,24 @@ instance semiringUnit :: Semiring Unit where
mul _ _ = unit
one = unit

instance semiringProxy :: Semiring (Proxy a) where
add _ _ = Proxy
mul _ _ = Proxy
one = Proxy
zero = Proxy

instance semiringProxy2 :: Semiring (Proxy2 a) where
add _ _ = Proxy2
mul _ _ = Proxy2
one = Proxy2
zero = Proxy2

instance semiringProxy3 :: Semiring (Proxy3 a) where
add _ _ = Proxy3
mul _ _ = Proxy3
one = Proxy3
zero = Proxy3

instance semiringRecord :: (RL.RowToList row list, SemiringRecord list row row) => Semiring (Record row) where
add = addRecord (RLProxy :: RLProxy list)
mul = mulRecord (RLProxy :: RLProxy list)
Expand Down
10 changes: 10 additions & 0 deletions src/Data/Show.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
import Prim.RowList as RL
import Record.Unsafe (unsafeGet)
import Type.Data.RowList (RLProxy(..))
import Type.Proxy (Proxy, Proxy2, Proxy3)

-- | The `Show` type class represents those types which can be converted into
-- | a human-readable `String` representation.
Expand Down Expand Up @@ -36,6 +37,15 @@ instance showString :: Show String where
instance showArray :: Show a => Show (Array a) where
show = showArrayImpl show

instance showProxy :: Show (Proxy a) where
show _ = "Proxy"

instance showProxy2 :: Show (Proxy2 a) where
show _ = "Proxy2"

instance showProxy3 :: Show (Proxy3 a) where
show _ = "Proxy3"

instance showRecord :: (RL.RowToList rs ls, ShowRecordFields ls rs) => Show (Record rs) where
show record = case showRecordFields (RLProxy :: RLProxy ls) record of
[] -> "{}"
Expand Down
Loading