Tupc.Internal
- Package
- purescript-tupc
- Repository
- rubenpieters/tupc
#DirectionX Source
#JsonConfig Source
type JsonConfig = { directionX :: DirectionX, directionY :: DirectionY, ignore :: Array Char, ignoreExtra :: Array Char, originX :: OriginX, originY :: OriginY, scale :: Int, scaleX :: Maybe Int, scaleY :: Maybe Int }#JsonConfigContent Source
type JsonConfigContent = { content :: Content, jsonConfig :: JsonConfig }#SubJsonConfigContent Source
type SubJsonConfigContent = { content :: Content, subJsonConfig :: SubRecord OptParams }#EnrichedPos Source
newtype EnrichedPosConstructors
EnrichedPos { xCenter :: Int, xLeft :: Int, xRight :: Int, xWidth :: Int, yBot :: Int, yCenter :: Int, yHeight :: Int, yTop :: Int }
Instances
Re-exports from Control.Monad.Eff
#Eff Source
data Eff :: Row Effect -> Type -> TypeThe Eff type constructor is used to represent native effects.
See Handling Native Effects with the Eff Monad for more details.
The first type parameter is a row of effects which represents the contexts in which a computation can be run, and the second type parameter is the return type.
Instances
Re-exports from Control.Monad.Eff.Console
Re-exports from Control.Monad.Eff.Exception
#throw
throw :: forall a eff. String -> Eff (exception :: EXCEPTION | eff) aA shortcut allowing you to throw an error in one step. Defined as
throwException <<< error.
Re-exports from Data.Array
#uncons Source
uncons :: forall a. Array a -> Maybe { head :: a, tail :: Array a }Break an array into its first element and remaining elements.
Using uncons provides a way of writing code that would use cons patterns
in Haskell or pre-PureScript 0.7:
f (x : xs) = something
f [] = somethingElse
Becomes:
f arr = case uncons arr of
Just { head: x, tail: xs } -> something
Nothing -> somethingElse
Re-exports from Data.Either
#Either Source
data Either a bThe Either type is used to represent a choice between two types of value.
A common use case for Either is error handling, where Left is used to
carry an error value and Right is used to carry a success value.
Constructors
Instances
Functor (Either a)Invariant (Either a)Bifunctor EitherApply (Either e)The
Applyinstance allows functions contained within aRightto transform a value contained within aRightusing the(<*>)operator:Right f <*> Right x == Right (f x)Leftvalues are left untouched:Left f <*> Right x == Left x Right f <*> Left y == Left yCombining
Functor's<$>withApply's<*>can be used to transform a pure function to takeEither-typed arguments sof :: a -> b -> cbecomesf :: Either l a -> Either l b -> Either l c:f <$> Right x <*> Right y == Right (f x y)The
Left-preserving behaviour of both operators means the result of an expression like the above but where any one of the values isLeftmeans the whole result becomesLeftalso, taking the firstLeftvalue found:f <$> Left x <*> Right y == Left x f <$> Right x <*> Left y == Left y f <$> Left x <*> Left y == Left xApplicative (Either e)The
Applicativeinstance enables lifting of values intoEitherwith thepurefunction:pure x :: Either _ _ == Right xCombining
Functor's<$>withApply's<*>andApplicative'spurecan be used to pass a mixture ofEitherand non-Eithertyped values to a function that does not usually expect them, by usingpurefor any value that is not alreadyEithertyped:f <$> Right x <*> pure y == Right (f x y)Even though
pure = Rightit is recommended to usepurein situations like this as it allows the choice ofApplicativeto be changed later without having to go through and replaceRightwith a new constructor.Alt (Either e)The
Altinstance allows for a choice to be made between twoEithervalues with the<|>operator, where the firstRightencountered is taken.Right x <|> Right y == Right x Left x <|> Right y == Right y Left x <|> Left y == Left yBind (Either e)The
Bindinstance allows sequencing ofEithervalues and functions that return anEitherby using the>>=operator:Left x >>= f = Left x Right x >>= f = f xMonad (Either e)The
Monadinstance guarantees that there are bothApplicativeandBindinstances forEither. This also enables thedosyntactic sugar:do x' <- x y' <- y pure (f x' y')Which is equivalent to:
x >>= (\x' -> y >>= (\y' -> pure (f x' y')))Extend (Either e)The
Extendinstance allows sequencing ofEithervalues and functions that accept anEitherand return a non-Eitherresult using the<<=operator.f <<= Left x = Left x f <<= Right x = Right (f (Right x))(Show a, Show b) => Show (Either a b)The
Showinstance allowsEithervalues to be rendered as a string withshowwhenever there is anShowinstance for both type theEithercan contain.(Eq a, Eq b) => Eq (Either a b)(Eq a) => Eq1 (Either a)(Ord a, Ord b) => Ord (Either a b)(Ord a) => Ord1 (Either a)(Bounded a, Bounded b) => Bounded (Either a b)Foldable (Either a)Bifoldable EitherTraversable (Either a)Bitraversable Either(Semiring b) => Semiring (Either a b)(Semigroup b) => Semigroup (Either a b)
#either Source
either :: forall c b a. (a -> c) -> (b -> c) -> Either a b -> cTakes two functions and an Either value, if the value is a Left the
inner value is applied to the first function, if the value is a Right
the inner value is applied to the second function.
either f g (Left x) == f x
either f g (Right y) == g y
Re-exports from Data.Foldable
#surroundMap
surroundMap :: forall m a f. Foldable f => Semigroup m => m -> (a -> m) -> f a -> mfoldMap but with each element surrounded by some fixed value.
For example:
> surroundMap "*" show []
= "*"
> surroundMap "*" show [1]
= "*1*"
> surroundMap "*" show [1, 2]
= "*1*2*"
> surroundMap "*" show [1, 2, 3]
= "*1*2*3*"
#surround
surround :: forall m f. Foldable f => Semigroup m => m -> f m -> mfold but with each element surrounded by some fixed value.
For example:
> surround "*" []
= "*"
> surround "*" ["1"]
= "*1*"
> surround "*" ["1", "2"]
= "*1*2*"
> surround "*" ["1", "2", "3"]
= "*1*2*3*"
#oneOfMap
oneOfMap :: forall b a g f. Foldable f => Plus g => (a -> g b) -> f a -> g bFolds a structure into some Plus.
#null
null :: forall f a. Foldable f => f a -> BooleanTest whether the structure is empty. Optimized for structures that are similar to cons-lists, because there is no general way to do better.
#length
length :: forall f b a. Foldable f => Semiring b => f a -> bReturns the size/length of a finite structure. Optimized for structures that are similar to cons-lists, because there is no general way to do better.
#indexr
indexr :: forall f a. Foldable f => Int -> f a -> Maybe aTry to get nth element from the right in a data structure
#indexl
indexl :: forall f a. Foldable f => Int -> f a -> Maybe aTry to get nth element from the left in a data structure
#foldM
foldM :: forall b a m f. Foldable f => Monad m => (a -> b -> m a) -> a -> f b -> m aSimilar to 'foldl', but the result is encapsulated in a monad.
Note: this function is not generally stack-safe, e.g., for monads which
build up thunks a la Eff.
#findMap
findMap :: forall f b a. Foldable f => (a -> Maybe b) -> f a -> Maybe bTry to find an element in a data structure which satisfies a predicate mapping.
Re-exports from Data.Map
#Map
data Map k vMap k v represents maps from keys of type k to values of type v.
Instances
(Eq k) => Eq1 (Map k)(Eq k, Eq v) => Eq (Map k v)(Ord k) => Ord1 (Map k)(Ord k, Ord v) => Ord (Map k v)(Show k, Show v) => Show (Map k v)(Ord k) => Semigroup (Map k v)(Ord k) => Monoid (Map k v)Functor (Map k)FunctorWithIndex k (Map k)Foldable (Map k)FoldableWithIndex k (Map k)Traversable (Map k)TraversableWithIndex k (Map k)
Re-exports from Data.Maybe
#Maybe Source
data Maybe aThe Maybe type is used to represent optional values and can be seen as
something like a type-safe null, where Nothing is null and Just x
is the non-null value x.
Constructors
Instances
Functor MaybeThe
Functorinstance allows functions to transform the contents of aJustwith the<$>operator:f <$> Just x == Just (f x)Nothingvalues are left untouched:f <$> Nothing == NothingApply MaybeThe
Applyinstance allows functions contained within aJustto transform a value contained within aJustusing theapplyoperator:Just f <*> Just x == Just (f x)Nothingvalues are left untouched:Just f <*> Nothing == Nothing Nothing <*> Just x == NothingCombining
Functor's<$>withApply's<*>can be used transform a pure function to takeMaybe-typed arguments sof :: a -> b -> cbecomesf :: Maybe a -> Maybe b -> Maybe c:f <$> Just x <*> Just y == Just (f x y)The
Nothing-preserving behaviour of both operators means the result of an expression like the above but where any one of the values isNothingmeans the whole result becomesNothingalso:f <$> Nothing <*> Just y == Nothing f <$> Just x <*> Nothing == Nothing f <$> Nothing <*> Nothing == NothingApplicative MaybeThe
Applicativeinstance enables lifting of values intoMaybewith thepureorreturnfunction (returnis an alias forpure):pure x :: Maybe _ == Just x return x :: Maybe _ == Just xCombining
Functor's<$>withApply's<*>andApplicative'spurecan be used to pass a mixture ofMaybeand non-Maybetyped values to a function that does not usually expect them, by usingpurefor any value that is not alreadyMaybetyped:f <$> Just x <*> pure y == Just (f x y)Even though
pure = Justit is recommended to usepurein situations like this as it allows the choice ofApplicativeto be changed later without having to go through and replaceJustwith a new constructor.Alt MaybeThe
Altinstance allows for a choice to be made between twoMaybevalues with the<|>operator, where the firstJustencountered is taken.Just x <|> Just y == Just x Nothing <|> Just y == Just y Nothing <|> Nothing == NothingPlus MaybeThe
Plusinstance provides a defaultMaybevalue:empty :: Maybe _ == NothingAlternative MaybeThe
Alternativeinstance guarantees that there are bothApplicativeandPlusinstances forMaybe.Bind MaybeThe
Bindinstance allows sequencing ofMaybevalues and functions that return aMaybeby using the>>=operator:Just x >>= f = f x Nothing >>= f = NothingMonad MaybeThe
Monadinstance guarantees that there are bothApplicativeandBindinstances forMaybe. This also enables thedosyntactic sugar:do x' <- x y' <- y pure (f x' y')Which is equivalent to:
x >>= (\x' -> y >>= (\y' -> pure (f x' y')))MonadZero MaybeExtend MaybeThe
Extendinstance allows sequencing ofMaybevalues and functions that accept aMaybe aand return a non-Mayberesult using the<<=operator.f <<= Nothing = Nothing f <<= Just x = Just (f x)Invariant Maybe(Semigroup a) => Semigroup (Maybe a)The
Semigroupinstance enables use of the operator<>onMaybevalues whenever there is aSemigroupinstance for the type theMaybecontains. The exact behaviour of<>depends on the "inner"Semigroupinstance, but generally captures the notion of appending or combining things.Just x <> Just y = Just (x <> y) Just x <> Nothing = Just x Nothing <> Just y = Just y Nothing <> Nothing = Nothing(Semigroup a) => Monoid (Maybe a)(Eq a) => Eq (Maybe a)Eq1 Maybe(Ord a) => Ord (Maybe a)Ord1 Maybe(Bounded a) => Bounded (Maybe a)(Show a) => Show (Maybe a)The
Showinstance allowsMaybevalues to be rendered as a string withshowwhenever there is anShowinstance for the type theMaybecontains.
#maybe' Source
maybe' :: forall b a. (Unit -> b) -> (a -> b) -> Maybe a -> bSimilar to maybe but for use in cases where the default value may be
expensive to compute. As PureScript is not lazy, the standard maybe has
to evaluate the default value before returning the result, whereas here
the value is only computed when the Maybe is known to be Nothing.
maybe' (\_ -> x) f Nothing == x
maybe' (\_ -> x) f (Just y) == f y
#maybe Source
maybe :: forall b a. b -> (a -> b) -> Maybe a -> bTakes a default value, a function, and a Maybe value. If the Maybe
value is Nothing the default value is returned, otherwise the function
is applied to the value inside the Just and the result is returned.
maybe x f Nothing == x
maybe x f (Just y) == f y
#fromMaybe' Source
fromMaybe' :: forall a. (Unit -> a) -> Maybe a -> aSimilar to fromMaybe but for use in cases where the default value may be
expensive to compute. As PureScript is not lazy, the standard fromMaybe
has to evaluate the default value before returning the result, whereas here
the value is only computed when the Maybe is known to be Nothing.
fromMaybe' (\_ -> x) Nothing == x
fromMaybe' (\_ -> x) (Just y) == y
Re-exports from Data.SubRecord
#SubRecord
data SubRecord :: Row Type -> TypeA SubRecord x is a record which may contain values for labels in x
as opposed to a Record x which must contain values for labels in x
Re-exports from Data.Symbol
#IsSymbol Source
class IsSymbol (sym :: Symbol) whereA class for known symbols
Members
reflectSymbol :: SProxy sym -> String
Instances
(IsSymbol left, IsSymbol right) => IsSymbol (TypeConcat left right)
#reifySymbol Source
reifySymbol :: forall r. String -> (forall sym. IsSymbol sym => SProxy sym -> r) -> rRe-exports from Data.Traversable
#Accum
type Accum s a = { accum :: s, value :: a }#Foldable
class Foldable f whereFoldable represents data structures which can be folded.
foldrfolds a structure from the rightfoldlfolds a structure from the leftfoldMapfolds a structure by accumulating values in aMonoid
Default implementations are provided by the following functions:
foldrDefaultfoldlDefaultfoldMapDefaultRfoldMapDefaultL
Note: some combinations of the default implementations are unsafe to use together - causing a non-terminating mutually recursive cycle. These combinations are documented per function.
Members
foldr :: forall b a. (a -> b -> b) -> b -> f a -> bfoldl :: forall b a. (b -> a -> b) -> b -> f a -> bfoldMap :: forall m a. Monoid m => (a -> m) -> f a -> m
Instances
Foldable ArrayFoldable MaybeFoldable FirstFoldable LastFoldable AdditiveFoldable DualFoldable DisjFoldable ConjFoldable Multiplicative
#Traversable
class (Functor t, Foldable t) <= Traversable t whereTraversable represents data structures which can be traversed,
accumulating results and effects in some Applicative functor.
traverseruns an action for every element in a data structure, and accumulates the results.sequenceruns the actions contained in a data structure, and accumulates the results.
The traverse and sequence functions should be compatible in the
following sense:
traverse f xs = sequence (f <$> xs)sequence = traverse id
Traversable instances should also be compatible with the corresponding
Foldable instances, in the following sense:
foldMap f = runConst <<< traverse (Const <<< f)
Default implementations are provided by the following functions:
traverseDefaultsequenceDefault
Members
traverse :: forall m b a. Applicative m => (a -> m b) -> t a -> m (t b)sequence :: forall m a. Applicative m => t (m a) -> m (t a)
Instances
Traversable ArrayTraversable MaybeTraversable FirstTraversable LastTraversable AdditiveTraversable DualTraversable ConjTraversable DisjTraversable Multiplicative
#traverse_
traverse_ :: forall m f b a. Applicative m => Foldable f => (a -> m b) -> f a -> m UnitTraverse a data structure, performing some effects encoded by an
Applicative functor at each value, ignoring the final result.
For example:
traverse_ print [1, 2, 3]
#traverseDefault
traverseDefault :: forall m b a t. Traversable t => Applicative m => (a -> m b) -> t a -> m (t b)A default implementation of traverse using sequence and map.
#sum
sum :: forall f a. Foldable f => Semiring a => f a -> aFind the sum of the numeric values in a data structure.
#sequence_
sequence_ :: forall m f a. Applicative m => Foldable f => f (m a) -> m UnitPerform all of the effects in some data structure in the order
given by the Foldable instance, ignoring the final result.
For example:
sequence_ [ trace "Hello, ", trace " world!" ]
#sequenceDefault
sequenceDefault :: forall m a t. Traversable t => Applicative m => t (m a) -> m (t a)A default implementation of sequence using traverse.
#scanr
scanr :: forall f b a. Traversable f => (a -> b -> b) -> b -> f a -> f bFold a data structure from the right, keeping all intermediate results
instead of only the final result. Note that the initial value does not
appear in the result (unlike Haskell's Prelude.scanr).
scanr (+) 0 [1,2,3] = [1,3,6]
scanr (flip (-)) 10 [1,2,3] = [4,5,7]
#scanl
scanl :: forall f b a. Traversable f => (b -> a -> b) -> b -> f a -> f bFold a data structure from the left, keeping all intermediate results
instead of only the final result. Note that the initial value does not
appear in the result (unlike Haskell's Prelude.scanl).
scanl (+) 0 [1,2,3] = [1,3,6]
scanl (-) 10 [1,2,3] = [9,7,4]
#product
product :: forall f a. Foldable f => Semiring a => f a -> aFind the product of the numeric values in a data structure.
#or
or :: forall f a. Foldable f => HeytingAlgebra a => f a -> aThe disjunction of all the values in a data structure. When specialized
to Boolean, this function will test whether any of the values in a data
structure is true.
#oneOf
oneOf :: forall a g f. Foldable f => Plus g => f (g a) -> g aCombines a collection of elements using the Alt operation.
#notElem
notElem :: forall f a. Foldable f => Eq a => a -> f a -> BooleanTest whether a value is not an element of a data structure.
#minimumBy
minimumBy :: forall f a. Foldable f => (a -> a -> Ordering) -> f a -> Maybe aFind the smallest element of a structure, according to a given comparison
function. The comparison function should represent a total ordering (see
the Ord type class laws); if it does not, the behaviour is undefined.
#minimum
minimum :: forall f a. Ord a => Foldable f => f a -> Maybe aFind the smallest element of a structure, according to its Ord instance.
#maximumBy
maximumBy :: forall f a. Foldable f => (a -> a -> Ordering) -> f a -> Maybe aFind the largest element of a structure, according to a given comparison
function. The comparison function should represent a total ordering (see
the Ord type class laws); if it does not, the behaviour is undefined.
#maximum
maximum :: forall f a. Ord a => Foldable f => f a -> Maybe aFind the largest element of a structure, according to its Ord instance.
#mapAccumR
mapAccumR :: forall f s b a. Traversable f => (s -> a -> Accum s b) -> s -> f a -> Accum s (f b)Fold a data structure from the right, keeping all intermediate results instead of only the final result.
Unlike scanr, mapAccumR allows the type of accumulator to differ
from the element type of the final data structure.
#mapAccumL
mapAccumL :: forall f s b a. Traversable f => (s -> a -> Accum s b) -> s -> f a -> Accum s (f b)Fold a data structure from the left, keeping all intermediate results instead of only the final result.
Unlike scanl, mapAccumL allows the type of accumulator to differ
from the element type of the final data structure.
#intercalate
intercalate :: forall m f. Foldable f => Monoid m => m -> f m -> mFold a data structure, accumulating values in some Monoid,
combining adjacent elements using the specified separator.
#for_
for_ :: forall m f b a. Applicative m => Foldable f => f a -> (a -> m b) -> m UnitA version of traverse_ with its arguments flipped.
This can be useful when running an action written using do notation for every element in a data structure:
For example:
for_ [1, 2, 3] \n -> do
print n
trace "squared is"
print (n * n)
#for
for :: forall t m b a. Applicative m => Traversable t => t a -> (a -> m b) -> m (t b)A version of traverse with its arguments flipped.
This can be useful when running an action written using do notation for every element in a data structure:
For example:
for [1, 2, 3] \n -> do
print n
return (n * n)
#foldrDefault
foldrDefault :: forall b a f. Foldable f => (a -> b -> b) -> b -> f a -> bA default implementation of foldr using foldMap.
Note: when defining a Foldable instance, this function is unsafe to use
in combination with foldMapDefaultR.
#foldlDefault
foldlDefault :: forall b a f. Foldable f => (b -> a -> b) -> b -> f a -> bA default implementation of foldl using foldMap.
Note: when defining a Foldable instance, this function is unsafe to use
in combination with foldMapDefaultL.
#foldMapDefaultR
foldMapDefaultR :: forall m a f. Foldable f => Monoid m => (a -> m) -> f a -> mA default implementation of foldMap using foldr.
Note: when defining a Foldable instance, this function is unsafe to use
in combination with foldrDefault.
#foldMapDefaultL
foldMapDefaultL :: forall m a f. Foldable f => Monoid m => (a -> m) -> f a -> mA default implementation of foldMap using foldl.
Note: when defining a Foldable instance, this function is unsafe to use
in combination with foldlDefault.
#fold
fold :: forall m f. Foldable f => Monoid m => f m -> mFold a data structure, accumulating values in some Monoid.
#find
find :: forall f a. Foldable f => (a -> Boolean) -> f a -> Maybe aTry to find an element in a data structure which satisfies a predicate.
#elem
elem :: forall f a. Foldable f => Eq a => a -> f a -> BooleanTest whether a value is an element of a data structure.
#any
any :: forall f b a. Foldable f => HeytingAlgebra b => (a -> b) -> f a -> bany f is the same as or <<< map f; map a function over the structure,
and then get the disjunction of the results.
#and
and :: forall f a. Foldable f => HeytingAlgebra a => f a -> aThe conjunction of all the values in a data structure. When specialized
to Boolean, this function will test whether all of the values in a data
structure are true.
#all
all :: forall f b a. Foldable f => HeytingAlgebra b => (a -> b) -> f a -> ball f is the same as and <<< map f; map a function over the structure,
and then get the conjunction of the results.
Re-exports from Data.Tuple
#Tuple Source
data Tuple a bA simple product type for wrapping a pair of component values.
Constructors
Tuple a b
Instances
(Show a, Show b) => Show (Tuple a b)Allows
Tuples to be rendered as a string withshowwhenever there areShowinstances for both component types.(Eq a, Eq b) => Eq (Tuple a b)(Eq a) => Eq1 (Tuple a)(Ord a, Ord b) => Ord (Tuple a b)(Ord a) => Ord1 (Tuple a)(Bounded a, Bounded b) => Bounded (Tuple a b)Semigroupoid Tuple(Semigroup a, Semigroup b) => Semigroup (Tuple a b)The
Semigroupinstance enables use of the associative operator<>onTuples whenever there areSemigroupinstances for the component types. The<>operator is applied pairwise, so:(Tuple a1 b1) <> (Tuple a2 b2) = Tuple (a1 <> a2) (b1 <> b2)(Monoid a, Monoid b) => Monoid (Tuple a b)(Semiring a, Semiring b) => Semiring (Tuple a b)(Ring a, Ring b) => Ring (Tuple a b)(CommutativeRing a, CommutativeRing b) => CommutativeRing (Tuple a b)(HeytingAlgebra a, HeytingAlgebra b) => HeytingAlgebra (Tuple a b)(BooleanAlgebra a, BooleanAlgebra b) => BooleanAlgebra (Tuple a b)Functor (Tuple a)The
Functorinstance allows functions to transform the contents of aTuplewith the<$>operator, applying the function to the second component, so:f <$> (Tuple x y) = Tuple x (f y)Invariant (Tuple a)Bifunctor Tuple(Semigroup a) => Apply (Tuple a)The
Functorinstance allows functions to transform the contents of aTuplewith the<*>operator whenever there is aSemigroupinstance for thefstcomponent, so:(Tuple a1 f) <*> (Tuple a2 x) == Tuple (a1 <> a2) (f x)Biapply Tuple(Monoid a) => Applicative (Tuple a)Biapplicative Tuple(Semigroup a) => Bind (Tuple a)(Monoid a) => Monad (Tuple a)Extend (Tuple a)Comonad (Tuple a)(Lazy a, Lazy b) => Lazy (Tuple a b)Foldable (Tuple a)Bifoldable TupleTraversable (Tuple a)Bitraversable Tuple(TypeEquals a Unit) => Distributive (Tuple a)
Re-exports from Prelude
#Void
newtype VoidAn uninhabited data type.
Void is useful to eliminate the possibility of a value being created.
For example, a value of type Either Void Boolean can never have
a Left value created in PureScript.
Instances
Show Void
#Unit
data Unit :: TypeThe Unit type has a single inhabitant, called unit. It represents
values with no computational content.
Unit is often used, wrapped in a monadic type constructor, as the
return type of a computation where only
the effects are important.
Instances
Show Unit
#Ordering
data OrderingThe 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
LTGTEQ
Instances
Eq OrderingSemigroup OrderingShow Ordering
#Applicative
class (Apply f) <= Applicative f whereThe 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
Applicative (Function r)Applicative Array
#Apply
class (Functor f) <= Apply f whereThe 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
Apply (Function r)Apply Array
#Bind
class (Apply m) <= Bind m whereThe 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
Bind (Function r)Bind Array
#BooleanAlgebra
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 BooleanBooleanAlgebra Unit(BooleanAlgebra b) => BooleanAlgebra (a -> b)
#Bounded
class (Ord a) <= Bounded a whereThe Bounded type class represents totally ordered types that have an
upper and lower boundary.
Instances should satisfy the following law in addition to the Ord laws:
- Bounded:
bottom <= a <= top
Members
top :: abottom :: a
Instances
Bounded BooleanBounded IntBounded CharCharacters fall within the Unicode range.
Bounded OrderingBounded Unit
#Category
class (Semigroupoid a) <= Category a whereCategorys 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
Category Function
#CommutativeRing
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
CommutativeRing IntCommutativeRing NumberCommutativeRing Unit(CommutativeRing b) => CommutativeRing (a -> b)
#Discard
class Discard a whereA class for types whose values can safely be discarded
in a do notation block.
An example is the Unit type, since there is only one
possible value which can be returned.
Members
discard :: forall b f. Bind f => f a -> (a -> f b) -> f b
Instances
Discard Unit
#DivisionRing
class (Ring a) <= DivisionRing a whereThe 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 = onefor 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
DivisionRing Number
#Eq
class Eq a whereThe 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 == yandy == zthenx == 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
eq :: a -> a -> Boolean
Instances
Eq BooleanEq IntEq NumberEq CharEq StringEq UnitEq Void(Eq a) => Eq (Array a)
#EuclideanRing
class (CommutativeRing a) <= EuclideanRing a whereThe 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 ifaandbare both nonzero then so is their producta * b - Euclidean function
degree:- Nonnegativity: For all nonzero
a,degree a >= 0 - Quotient/remainder: For all
aandb, wherebis nonzero, letq = a / bandr = a `mod` b; thena = q*b + r, and also eitherr = zeroordegree r < degree b
- Nonnegativity: For all nonzero
- Submultiplicative euclidean function:
- For all nonzero
aandb,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
degree :: a -> Intdiv :: a -> a -> amod :: a -> a -> a
Instances
EuclideanRing IntEuclideanRing Number
#Field
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 = zerofor allaandb
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
Field Number
#Functor
class Functor f whereA 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
Functor (Function r)Functor Array
#HeytingAlgebra
class HeytingAlgebra a whereThe 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) || ca && (b && c) = (a && b) && c
- Commutativity:
a || b = b || aa && b = b && a
- Absorption:
a || (a && b) = aa && (a || b) = a
- Idempotent:
a || a = aa && a = a
- Identity:
a || ff = aa && tt = a
- Implication:
a `implies` a = tta && (a `implies` b) = a && bb && (a `implies` b) = ba `implies` (b && c) = (a `implies` b) && (a `implies` c)
- Complemented:
not a = a `implies` ff
Members
conj :: a -> a -> adisj :: a -> a -> anot :: a -> a
Instances
HeytingAlgebra BooleanHeytingAlgebra Unit(HeytingAlgebra b) => HeytingAlgebra (a -> b)
#Monad
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
Monad (Function r)Monad Array
#Ord
class (Eq a) <= Ord a whereThe Ord type class represents types which support comparisons with a
total order.
Ord instances should satisfy the laws of total orderings:
- Reflexivity:
a <= a - Antisymmetry: if
a <= bandb <= athena = b - Transitivity: if
a <= bandb <= cthena <= c
Members
compare :: a -> a -> Ordering
Instances
Ord BooleanOrd IntOrd NumberOrd StringOrd CharOrd UnitOrd Void(Ord a) => Ord (Array a)Ord Ordering
#Ring
class (Semiring a) <= Ring a whereThe Ring class is for types that support addition, multiplication,
and subtraction operations.
Instances must satisfy the following law in addition to the Semiring
laws:
- Additive inverse:
a - a = (zero - a) + a = zero
Members
sub :: a -> a -> a
Instances
Ring IntRing NumberRing Unit(Ring b) => Ring (a -> b)
#Semigroup
class Semigroup a whereThe 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
Semigroup StringSemigroup UnitSemigroup Void(Semigroup s') => Semigroup (s -> s')Semigroup (Array a)
#Semigroupoid
class Semigroupoid a whereA Semigroupoid is similar to a Category but does not
require an identity element id, just composable morphisms.
Semigroupoids 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
Semigroupoid Function
#Semiring
class Semiring a whereThe 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
add :: a -> a -> azero :: amul :: a -> a -> aone :: a
Instances
Semiring IntSemiring Number(Semiring b) => Semiring (a -> b)Semiring Unit
#Show
class Show a whereThe 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
show :: a -> String
Instances
Show BooleanShow IntShow NumberShow CharShow String(Show a) => Show (Array a)
#whenM
whenM :: forall m. Monad m => m Boolean -> m Unit -> m UnitPerform a monadic action when a condition is true, where the conditional value is also in a monadic context.
#when
when :: forall m. Applicative m => Boolean -> m Unit -> m UnitPerform an applicative action when a condition is true.
#void
void :: forall a f. Functor f => f a -> f UnitThe 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)
#unlessM
unlessM :: forall m. Monad m => m Boolean -> m Unit -> m UnitPerform a monadic action unless a condition is true, where the conditional value is also in a monadic context.
#unless
unless :: forall m. Applicative m => Boolean -> m Unit -> m UnitPerform an applicative action unless a condition is true.
#unit
unit :: Unitunit is the sole inhabitant of the Unit type.
#otherwise
otherwise :: BooleanAn alias for true, which can be useful in guard clauses:
max x y | x >= y = x
| otherwise = y
#notEq
notEq :: forall a. Eq a => a -> a -> BooleannotEq tests whether one value is not equal to another. Shorthand for
not (eq x y).
#negate
negate :: forall a. Ring a => a -> anegate x can be used as a shorthand for zero - x.
#min
min :: forall a. Ord a => a -> a -> aTake the minimum of two values. If they are considered equal, the first argument is chosen.
#max
max :: forall a. Ord a => a -> a -> aTake the maximum of two values. If they are considered equal, the first argument is chosen.
#liftM1
liftM1 :: forall b a m. Monad m => (a -> b) -> m a -> m bliftM1 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
liftA1 :: forall b a f. Applicative f => (a -> b) -> f a -> f bliftA1 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
lcm :: forall a. Eq a => EuclideanRing a => a -> a -> aThe least common multiple of two values.
#join
join :: forall m a. Bind m => m (m a) -> m aCollapse two applications of a monadic type constructor into one.
#ifM
ifM :: forall m a. Bind m => m Boolean -> m a -> m a -> m aExecute a monadic action if a condition holds.
For example:
main = ifM ((< 0.5) <$> random)
(trace "Heads")
(trace "Tails")
#gcd
gcd :: forall a. Eq a => EuclideanRing a => a -> a -> aThe greatest common divisor of two values.
#flip
flip :: forall c b a. (a -> b -> c) -> b -> a -> cFlips the order of the arguments to a function of two arguments.
flip const 1 2 = const 2 1 = 2
#flap
flap :: forall b a f. Functor f => f (a -> b) -> a -> f bApply 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
const :: forall b a. a -> b -> aReturns its first argument and ignores its second.
const 1 "hello" = 1
#comparing
comparing :: forall b a. Ord b => (a -> b) -> (a -> a -> Ordering)Compares two values by mapping them to a type with an Ord instance.
#clamp
clamp :: forall a. Ord a => a -> a -> a -> aClamp a value between a minimum and a maximum. For example:
let f = clamp 0 10
f (-5) == 0
f 5 == 5
f 15 == 10
#between
between :: forall a. Ord a => a -> a -> a -> BooleanTest whether a value is between a minimum and a maximum (inclusive). For example:
let f = between 0 10
f 0 == true
f (-5) == false
f 5 == true
f 10 == true
f 15 == false
#ap
ap :: forall b a m. Monad m => m (a -> b) -> m a -> m bap provides a default implementation of (<*>) for any
Monad, without using (<*>) as provided by the
Apply-Monad superclass relationship.
ap can therefore be used to write Apply instances as
follows:
instance applyF :: Apply F where
apply = ap
#absurd
absurd :: forall a. Void -> a#(||)
Operator alias for Data.HeytingAlgebra.disj (right-associative / precedence 2)
#(>>>)
Operator alias for Control.Semigroupoid.composeFlipped (right-associative / precedence 9)
#(>>=)
Operator alias for Control.Bind.bind (left-associative / precedence 1)
#(>=>)
Operator alias for Control.Bind.composeKleisli (right-associative / precedence 1)
#(>=)
Operator alias for Data.Ord.greaterThanOrEq (left-associative / precedence 4)
#(>)
Operator alias for Data.Ord.greaterThan (left-associative / precedence 4)
#(==)
Operator alias for Data.Eq.eq (non-associative / precedence 4)
#(=<<)
Operator alias for Control.Bind.bindFlipped (right-associative / precedence 1)
#(<@>)
Operator alias for Data.Functor.flap (left-associative / precedence 4)
#(<>)
Operator alias for Data.Semigroup.append (right-associative / precedence 5)
#(<=<)
Operator alias for Control.Bind.composeKleisliFlipped (right-associative / precedence 1)
#(<=)
Operator alias for Data.Ord.lessThanOrEq (left-associative / precedence 4)
#(<<<)
Operator alias for Control.Semigroupoid.compose (right-associative / precedence 9)
#(<*>)
Operator alias for Control.Apply.apply (left-associative / precedence 4)
#(<*)
Operator alias for Control.Apply.applyFirst (left-associative / precedence 4)
#(<$>)
Operator alias for Data.Functor.map (left-associative / precedence 4)
#(<$)
Operator alias for Data.Functor.voidRight (left-associative / precedence 4)
#(<#>)
Operator alias for Data.Functor.mapFlipped (left-associative / precedence 1)
#(<)
Operator alias for Data.Ord.lessThan (left-associative / precedence 4)
#(/=)
Operator alias for Data.Eq.notEq (non-associative / precedence 4)
#(/)
Operator alias for Data.EuclideanRing.div (left-associative / precedence 7)
#(-)
Operator alias for Data.Ring.sub (left-associative / precedence 6)
#(+)
Operator alias for Data.Semiring.add (left-associative / precedence 6)
#(*>)
Operator alias for Control.Apply.applySecond (left-associative / precedence 4)
#(*)
Operator alias for Data.Semiring.mul (left-associative / precedence 7)
#(&&)
Operator alias for Data.HeytingAlgebra.conj (right-associative / precedence 3)
#($>)
Operator alias for Data.Functor.voidLeft (left-associative / precedence 4)
#($)
Operator alias for Data.Function.apply (right-associative / precedence 0)
Applies a function to an argument: the reverse of (#).
length $ groupBy productCategory $ filter isInStock $ products
is equivalent to:
length (groupBy productCategory (filter isInStock products))
Or another alternative equivalent, applying chain of composed functions to a value:
length <<< groupBy productCategory <<< filter isInStock $ products
#(#)
Operator alias for Data.Function.applyFlipped (left-associative / precedence 1)
Applies an argument to a function: the reverse of ($).
products # filter isInStock # groupBy productCategory # length
is equivalent to:
length (groupBy productCategory (filter isInStock products))
Or another alternative equivalent, applying a value to a chain of composed functions:
products # filter isInStock >>> groupBy productCategory >>> length
#type (~>)
Operator alias for Data.NaturalTransformation.NaturalTransformation (right-associative / precedence 4)
The
Functorinstance allows functions to transform the contents of aRightwith the<$>operator:Leftvalues are untouched: