Paxl
- Package
- purescript-paxl
- Repository
- jqyu/purescript-paxl
#PaxlEffects Source
type PaxlEffects reqs eff = GenPaxlEffects (Fetch reqs) eff
Re-exports from Paxl.Prelude
#Ordering Source
data Ordering
The Ordering
data type represents the three possible outcomes of
comparing two values:
LT
- The first value is less than the second.
GT
- The first value is greater than the second.
EQ
- The first value is equal to the second.
Constructors
Instances
#Applicative Source
class (Apply f) <= Applicative f where
The Applicative
type class extends the Apply
type class
with a pure
function, which can be used to create values of type f a
from values of type a
.
Where Apply
provides the ability to lift functions of two or
more arguments to functions whose arguments are wrapped using f
, and
Functor
provides the ability to lift functions of one
argument, pure
can be seen as the function which lifts functions of
zero arguments. That is, Applicative
functors support a lifting
operation for any number of function arguments.
Instances must satisfy the following laws in addition to the Apply
laws:
- Identity:
(pure id) <*> v = v
- Composition:
pure (<<<) <*> f <*> g <*> h = f <*> (g <*> h)
- Homomorphism:
(pure f) <*> (pure x) = pure (f x)
- Interchange:
u <*> (pure y) = (pure (_ $ y)) <*> u
Members
pure :: forall a. a -> f a
Instances
#Apply Source
class (Functor f) <= Apply f where
The Apply
class provides the (<*>)
which is used to apply a function
to an argument under a type constructor.
Apply
can be used to lift functions of two or more arguments to work on
values wrapped with the type constructor f
. It might also be understood
in terms of the lift2
function:
lift2 :: forall f a b c. Apply f => (a -> b -> c) -> f a -> f b -> f c
lift2 f a b = f <$> a <*> b
(<*>)
is recovered from lift2
as lift2 ($)
. That is, (<*>)
lifts
the function application operator ($)
to arguments wrapped with the
type constructor f
.
Instances must satisfy the following law in addition to the Functor
laws:
- Associative composition:
(<<<) <$> f <*> g <*> h = f <*> (g <*> h)
Formally, Apply
represents a strong lax semi-monoidal endofunctor.
Members
apply :: forall b a. f (a -> b) -> f a -> f b
Instances
#Bind Source
class (Apply m) <= Bind m where
The Bind
type class extends the Apply
type class with a
"bind" operation (>>=)
which composes computations in sequence, using
the return value of one computation to determine the next computation.
The >>=
operator can also be expressed using do
notation, as follows:
x >>= f = do y <- x
f y
where the function argument of f
is given the name y
.
Instances must satisfy the following law in addition to the Apply
laws:
- Associativity:
(x >>= f) >>= g = x >>= (\k -> f k >>= g)
Associativity tells us that we can regroup operations which use do
notation so that we can unambiguously write, for example:
do x <- m1
y <- m2 x
m3 x y
Members
bind :: forall b a. m a -> (a -> m b) -> m b
Instances
#BooleanAlgebra Source
class (HeytingAlgebra a) <= BooleanAlgebra a
The BooleanAlgebra
type class represents types that behave like boolean
values.
Instances should satisfy the following laws in addition to the
HeytingAlgebra
law:
- Excluded middle:
a || not a = tt
Instances
BooleanAlgebra Boolean
BooleanAlgebra Unit
(BooleanAlgebra b) => BooleanAlgebra (a -> b)
#Bounded Source
#Category Source
class (Semigroupoid a) <= Category a where
Category
s consist of objects and composable morphisms between them, and
as such are Semigroupoids
, but unlike semigroupoids
must have an identity element.
Instances must satisfy the following law in addition to the
Semigroupoid
law:
- Identity:
id <<< p = p <<< id = p
Members
id :: forall t. a t t
Instances
#CommutativeRing Source
class (Ring a) <= CommutativeRing a
The CommutativeRing
class is for rings where multiplication is
commutative.
Instances must satisfy the following law in addition to the Ring
laws:
- Commutative multiplication:
a * b = b * a
Instances
#DivisionRing Source
class (Ring a) <= DivisionRing a where
The DivisionRing
class is for non-zero rings in which every non-zero
element has a multiplicative inverse. Division rings are sometimes also
called skew fields.
Instances must satisfy the following laws in addition to the Ring
laws:
- Non-zero ring:
one /= zero
- Non-zero multiplicative inverse:
recip a * a = a * recip a = one
for all non-zeroa
The result of recip zero
is left undefined; individual instances may
choose how to handle this case.
If a type has both DivisionRing
and CommutativeRing
instances, then
it is a field and should have a Field
instance.
Members
recip :: a -> a
Instances
#Eq Source
class Eq a where
The Eq
type class represents types which support decidable equality.
Eq
instances should satisfy the following laws:
- Reflexivity:
x == x = true
- Symmetry:
x == y = y == x
- Transitivity: if
x == y
andy == z
thenx == z
Note: The Number
type is not an entirely law abiding member of this
class due to the presence of NaN
, since NaN /= NaN
. Additionally,
computing with Number
can result in a loss of precision, so sometimes
values that should be equivalent are not.
Members
Instances
#EuclideanRing Source
class (CommutativeRing a) <= EuclideanRing a where
The EuclideanRing
class is for commutative rings that support division.
The mathematical structure this class is based on is sometimes also called
a Euclidean domain.
Instances must satisfy the following laws in addition to the Ring
laws:
- Integral domain:
one /= zero
, and ifa
andb
are both nonzero then so is their producta * b
- Euclidean function
degree
:- Nonnegativity: For all nonzero
a
,degree a >= 0
- Quotient/remainder: For all
a
andb
, whereb
is nonzero, letq = a / b
andr = a `mod` b
; thena = q*b + r
, and also eitherr = zero
ordegree r < degree b
- Nonnegativity: For all nonzero
- Submultiplicative euclidean function:
- For all nonzero
a
andb
,degree a <= degree (a * b)
- For all nonzero
The behaviour of division by zero
is unconstrained by these laws,
meaning that individual instances are free to choose how to behave in this
case. Similarly, there are no restrictions on what the result of
degree zero
is; it doesn't make sense to ask for degree zero
in the
same way that it doesn't make sense to divide by zero
, so again,
individual instances may choose how to handle this case.
For any EuclideanRing
which is also a Field
, one valid choice
for degree
is simply const 1
. In fact, unless there's a specific
reason not to, Field
types should normally use this definition of
degree
.
Members
Instances
#Field Source
class (EuclideanRing a) <= Field a
The Field
class is for types that are (commutative) fields.
Instances must satisfy the following law in addition to the
EuclideanRing
laws:
- Non-zero multiplicative inverse:
a `mod` b = zero
for alla
andb
If a type has a Field
instance, it should also have a DivisionRing
instance. In a future release, DivisionRing
may become a superclass of
Field
.
Instances
#Functor Source
class Functor f where
A Functor
is a type constructor which supports a mapping operation
map
.
map
can be used to turn functions a -> b
into functions
f a -> f b
whose argument and return types use the type constructor f
to represent some computational context.
Instances must satisfy the following laws:
- Identity:
map id = id
- Composition:
map (f <<< g) = map f <<< map g
Members
map :: forall b a. (a -> b) -> f a -> f b
Instances
#HeytingAlgebra Source
class HeytingAlgebra a where
The HeytingAlgebra
type class represents types that are bounded lattices with
an implication operator such that the following laws hold:
- Associativity:
a || (b || c) = (a || b) || c
a && (b && c) = (a && b) && c
- Commutativity:
a || b = b || a
a && b = b && a
- Absorption:
a || (a && b) = a
a && (a || b) = a
- Idempotent:
a || a = a
a && a = a
- Identity:
a || ff = a
a && tt = a
- Implication:
a `implies` a = tt
a && (a `implies` b) = a && b
b && (a `implies` b) = b
a `implies` (b && c) = (a `implies` b) && (a `implies` c)
- Complemented:
not a = a `implies` ff
Members
Instances
HeytingAlgebra Boolean
HeytingAlgebra Unit
(HeytingAlgebra b) => HeytingAlgebra (a -> b)
#Monad Source
class (Applicative m, Bind m) <= Monad m
The Monad
type class combines the operations of the Bind
and
Applicative
type classes. Therefore, Monad
instances represent type
constructors which support sequential composition, and also lifting of
functions of arbitrary arity.
Instances must satisfy the following laws in addition to the
Applicative
and Bind
laws:
- Left Identity:
pure x >>= f = f x
- Right Identity:
x >>= pure = x
Instances
#Ord Source
#Ring Source
#Semigroup Source
class Semigroup a where
The Semigroup
type class identifies an associative operation on a type.
Instances are required to satisfy the following law:
- Associativity:
(x <> y) <> z = x <> (y <> z)
One example of a Semigroup
is String
, with (<>)
defined as string
concatenation.
Members
append :: a -> a -> a
Instances
#Semigroupoid Source
class Semigroupoid a where
A Semigroupoid
is similar to a Category
but does not
require an identity element id
, just composable morphisms.
Semigroupoid
s must satisfy the following law:
- Associativity:
p <<< (q <<< r) = (p <<< q) <<< r
One example of a Semigroupoid
is the function type constructor (->)
,
with (<<<)
defined as function composition.
Members
compose :: forall d c b. a c d -> a b c -> a b d
Instances
#Semiring Source
class Semiring a where
The Semiring
class is for types that support an addition and
multiplication operation.
Instances must satisfy the following laws:
- Commutative monoid under addition:
- Associativity:
(a + b) + c = a + (b + c)
- Identity:
zero + a = a + zero = a
- Commutative:
a + b = b + a
- Associativity:
- Monoid under multiplication:
- Associativity:
(a * b) * c = a * (b * c)
- Identity:
one * a = a * one = a
- Associativity:
- Multiplication distributes over addition:
- Left distributivity:
a * (b + c) = (a * b) + (a * c)
- Right distributivity:
(a + b) * c = (a * c) + (b * c)
- Left distributivity:
- Annihilation:
zero * a = a * zero = zero
Note: The Number
and Int
types are not fully law abiding
members of this class hierarchy due to the potential for arithmetic
overflows, and in the case of Number
, the presence of NaN
and
Infinity
values. The behaviour is unspecified in these cases.
Members
Instances
#Show Source
class Show a where
The Show
type class represents those types which can be converted into
a human-readable String
representation.
While not required, it is recommended that for any expression x
, the
string show x
be executable PureScript code which evaluates to the same
value as the expression x
.
Members
Instances
#when Source
when :: forall m. Applicative m => Boolean -> m Unit -> m Unit
Perform an applicative action when a condition is true.
#void Source
void :: forall a f. Functor f => f a -> f Unit
The void
function is used to ignore the type wrapped by a
Functor
, replacing it with Unit
and keeping only the type
information provided by the type constructor itself.
void
is often useful when using do
notation to change the return type
of a monadic computation:
main = forE 1 10 \n -> void do
print n
print (n * n)
#unless Source
unless :: forall m. Applicative m => Boolean -> m Unit -> m Unit
Perform an applicative action unless a condition is true.
#liftM1 Source
liftM1 :: forall b a m. Monad m => (a -> b) -> m a -> m b
liftM1
provides a default implementation of (<$>)
for any
Monad
, without using (<$>)
as provided by the
Functor
-Monad
superclass relationship.
liftM1
can therefore be used to write Functor
instances
as follows:
instance functorF :: Functor F where
map = liftM1
#liftA1 Source
liftA1 :: forall b a f. Applicative f => (a -> b) -> f a -> f b
liftA1
provides a default implementation of (<$>)
for any
Applicative
functor, without using (<$>)
as provided
by the Functor
-Applicative
superclass
relationship.
liftA1
can therefore be used to write Functor
instances
as follows:
instance functorF :: Functor F where
map = liftA1
#lcm Source
lcm :: forall a. Eq a => EuclideanRing a => a -> a -> a
The least common multiple of two values.
#gcd Source
gcd :: forall a. Eq a => EuclideanRing a => a -> a -> a
The greatest common divisor of two values.
#flip Source
flip :: forall c b a. (a -> b -> c) -> b -> a -> c
Flips the order of the arguments to a function of two arguments.
flip const 1 2 = const 2 1 = 2
#flap Source
flap :: forall b a f. Functor f => f (a -> b) -> a -> f b
Apply a value in a computational context to a value in no context.
Generalizes flip
.
longEnough :: String -> Bool
hasSymbol :: String -> Bool
hasDigit :: String -> Bool
password :: String
validate :: String -> List Bool
validate = flap [longEnough, hasSymbol, hasDigit]
flap (-) 3 4 == 1
threeve <$> Just 1 <@> 'a' <*> Just true == Just (threeve 1 'a' true)
#const Source
const :: forall b a. a -> b -> a
Returns its first argument and ignores its second.
const 1 "hello" = 1
#compose Source
compose :: forall a d c b. Semigroupoid a => a c d -> a b c -> a b d
#(>>>) Source
Operator alias for Control.Semigroupoid.composeFlipped (right-associative / precedence 9)
#(>>) Source
Operator alias for Control.Semigroupoid.composeFlipped (left-associative / precedence 9)
#(<=<) Source
Operator alias for Control.Bind.composeKleisliFlipped (right-associative / precedence 1)
#type (~>) Source
Operator alias for Data.NaturalTransformation.NaturalTransformation (right-associative / precedence 4)
Characters fall within the Unicode range.