MasonPrelude
- Package
- purescript-mason-prelude
- Repository
- ursi/purescript-mason-prelude
Re-exports from Control.Alt
#Alt Source
class (Functor f) <= Alt f The Alt type class identifies an associative operation on a type
constructor. It is similar to Semigroup, except that it applies to
types of kind * -> *, like Array or List, rather than concrete types
String or Number.
Alt instances are required to satisfy the following laws:
- Associativity:
(x <|> y) <|> z == x <|> (y <|> z) - Distributivity:
f <$> (x <|> y) == (f <$> x) <|> (f <$> y)
For example, the Array ([]) type is an instance of Alt, where
(<|>) is defined to be concatenation.
Instances
Re-exports from Control.Apply
Re-exports from Control.Parallel
#parTraverse_ Source
parTraverse_ :: forall b a t m f. Parallel f m => Foldable t => (a -> m b) -> t a -> m UnitTraverse a collection in parallel, discarding any results.
#parTraverse Source
parTraverse :: forall b a t m f. Parallel f m => Traversable t => (a -> m b) -> t a -> m (t b)Traverse a collection in parallel.
#parSequence Source
parSequence :: forall f m t a. Parallel f m => Traversable t => t (m a) -> m (t a)#parOneOfMap Source
parOneOfMap :: forall f m t b a. Parallel f m => Alternative f => Foldable t => Functor t => (a -> m b) -> t a -> m bRace a collection in parallel while mapping to some effect.
#parOneOf Source
parOneOf :: forall f m t a. Parallel f m => Alternative f => Foldable t => Functor t => t (m a) -> m aRace a collection in parallel.
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)FunctorWithIndex Unit (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)The
Eqinstance allowsEithervalues to be checked for equality with==and inequality with/=whenever there is anEqinstance for both types theEithercan contain.(Eq a) => Eq1 (Either a)(Ord a, Ord b) => Ord (Either a b)The
Ordinstance allowsEithervalues to be compared withcompare,>,>=,<and<=whenever there is anOrdinstance for both types theEithercan contain.Any
Leftvalue is considered to be less than aRightvalue.(Ord a) => Ord1 (Either a)(Bounded a, Bounded b) => Bounded (Either a b)Foldable (Either a)FoldableWithIndex Unit (Either a)Bifoldable EitherTraversable (Either a)TraversableWithIndex Unit (Either a)Bitraversable Either(Semigroup b) => Semigroup (Either a b)
Re-exports from Data.Either.Nested
Re-exports from Data.Foldable
#Foldable Source
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
#traverse_ Source
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]
#sequence_ Source
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!" ]
#intercalate Source
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 example:
> intercalate ", " ["Lorem", "ipsum", "dolor"]
= "Lorem, ipsum, dolor"
> intercalate "*" ["a", "b", "c"]
= "a*b*c"
> intercalate [1] [[2, 3], [4, 5], [6, 7]]
= [2, 3, 1, 4, 5, 1, 6, 7]
Re-exports from Data.FoldableWithIndex
#FoldableWithIndex Source
class (Foldable f) <= FoldableWithIndex i f | f -> i whereA Foldable with an additional index.
A FoldableWithIndex instance must be compatible with its Foldable
instance
foldr f = foldrWithIndex (const f)
foldl f = foldlWithIndex (const f)
foldMap f = foldMapWithIndex (const f)
Default implementations are provided by the following functions:
foldrWithIndexDefaultfoldlWithIndexDefaultfoldMapWithIndexDefaultRfoldMapWithIndexDefaultL
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
foldrWithIndex :: forall b a. (i -> a -> b -> b) -> b -> f a -> bfoldlWithIndex :: forall b a. (i -> b -> a -> b) -> b -> f a -> bfoldMapWithIndex :: forall m a. Monoid m => (i -> a -> m) -> f a -> m
Instances
Re-exports from Data.Function.Uncurried
Re-exports from Data.FunctorWithIndex
#FunctorWithIndex Source
class (Functor f) <= FunctorWithIndex i f | f -> i whereA Functor with an additional index.
Instances must satisfy a modified form of the Functor laws
mapWithIndex (\_ a -> a) = identity
mapWithIndex f . mapWithIndex g = mapWithIndex (\i -> f i <<< g i)
and be compatible with the Functor instance
map f = mapWithIndex (const f)
Members
mapWithIndex :: forall b a. (i -> a -> b) -> f a -> f b
Instances
Re-exports from Data.Generic.Rep
#Generic Source
class Generic a rep | a -> repThe Generic class asserts the existence of a type function from types
to their representations using the type constructors defined in this module.
Instances
Generic (Maybe a) (Sum (Constructor "Nothing" NoArguments) (Constructor "Just" (Argument a)))
Re-exports from Data.Generic.Rep.Show
#genericShow Source
genericShow :: forall rep a. Generic a rep => GenericShow rep => a -> StringA Generic implementation of the show member from the Show type class.
Re-exports from Data.Int
Re-exports from Data.List
#List Source
data List aConstructors
Instances
(Show a) => Show (List a)(Eq a) => Eq (List a)Eq1 List(Ord a) => Ord (List a)Ord1 ListSemigroup (List a)Monoid (List a)Functor ListFunctorWithIndex Int ListFoldable ListFoldableWithIndex Int ListUnfoldable1 ListUnfoldable ListTraversable ListTraversableWithIndex Int ListApply ListApplicative ListBind ListMonad ListAlt ListPlus ListAlternative ListMonadZero ListMonadPlus ListExtend List
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 thepurefunction:pure 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 <<= 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)The
Eqinstance allowsMaybevalues to be checked for equality with==and inequality with/=whenever there is anEqinstance for the type theMaybecontains.Eq1 Maybe(Ord a) => Ord (Maybe a)The
Ordinstance allowsMaybevalues to be compared withcompare,>,>=,<and<=whenever there is anOrdinstance for the type theMaybecontains.Nothingis considered to be less than anyJustvalue.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. 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
Re-exports from Data.String
#toUpper
toUpper :: String -> StringReturns the argument converted to uppercase.
toUpper "Hello" == "HELLO"
#toLower
toLower :: String -> StringReturns the argument converted to lowercase.
toLower "hElLo" == "hello"
Re-exports from Data.String.CodeUnits
#toCharArray
toCharArray :: String -> Array CharConverts the string into an array of characters.
toCharArray "Hello☺\n" == ['H','e','l','l','o','☺','\n']
#fromCharArray
fromCharArray :: Array Char -> StringConverts an array of characters into a string.
fromCharArray ['H', 'e', 'l', 'l', 'o'] == "Hello"
Re-exports from Data.Traversable
#Traversable Source
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 identity
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
Re-exports from Data.TraversableWithIndex
#TraversableWithIndex Source
class (FunctorWithIndex i t, FoldableWithIndex i t, Traversable t) <= TraversableWithIndex i t | t -> i whereA Traversable with an additional index.
A TraversableWithIndex instance must be compatible with its
Traversable instance
traverse f = traverseWithIndex (const f)
with its FoldableWithIndex instance
foldMapWithIndex f = unwrap <<< traverseWithIndex (\i -> Const <<< f i)
and with its FunctorWithIndex instance
mapWithIndex f = unwrap <<< traverseWithIndex (\i -> Identity <<< f i)
A default implementation is provided by traverseWithIndexDefault.
Members
traverseWithIndex :: forall m b a. Applicative m => (i -> a -> m b) -> t a -> m (t b)
Instances
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)Allows
Tuples to be checked for equality with==and/=whenever there areEqinstances for both component types.(Eq a) => Eq1 (Tuple a)(Ord a, Ord b) => Ord (Tuple a b)Allows
Tuples to be compared withcompare,>,>=,<and<=whenever there areOrdinstances for both component types. To obtain the result, thefsts arecompared, and if they areEQual, thesnds arecompared.(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)FunctorWithIndex Unit (Tuple a)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)Foldable1 (Tuple a)FoldableWithIndex Unit (Tuple a)Bifoldable TupleTraversable (Tuple a)Traversable1 (Tuple a)TraversableWithIndex Unit (Tuple a)Bitraversable Tuple(TypeEquals a Unit) => Distributive (Tuple a)
Re-exports from Data.Tuple.Nested
#(/\) Source
Operator alias for Data.Tuple.Tuple (right-associative / precedence 6)
Shorthand for constructing n-tuples as nested pairs.
a /\ b /\ c /\ d /\ unit becomes Tuple a (Tuple b (Tuple c (Tuple d unit)))
#type (/\) Source
Operator alias for Data.Tuple.Tuple (right-associative / precedence 6)
Shorthand for constructing n-tuple types as nested pairs.
forall a b c d. a /\ b /\ c /\ d /\ Unit becomes
forall a b c d. Tuple a (Tuple b (Tuple c (Tuple d Unit)))
Re-exports from Data.Unfoldable
#Unfoldable Source
class (Unfoldable1 t) <= Unfoldable t whereThis class identifies (possibly empty) data structures which can be unfolded.
The generating function f in unfoldr f is understood as follows:
- If
f bisNothing, thenunfoldr f bshould be empty. - If
f bisJust (Tuple a b1), thenunfoldr f bshould consist ofaappended to the result ofunfoldr f b1.
Note that it is not possible to give Unfoldable instances to types which
represent structures which are guaranteed to be non-empty, such as
NonEmptyArray: consider what unfoldr (const Nothing) should produce.
Structures which are guaranteed to be non-empty can instead be given
Unfoldable1 instances.
Members
Instances
Re-exports from Debug
#todo Source
todo :: forall a. aA placeholder to use when you want your code to compile without finishing something.
Re-exports from Effect
#Effect Source
data Effect :: Type -> TypeA native effect. The type parameter denotes the return type of running the
effect, that is, an Effect Int is a possibly-effectful computation which
eventually produces a value of the type Int when it finishes.
Instances
Functor EffectApply EffectApplicative EffectBind EffectMonad Effect(Semigroup a) => Semigroup (Effect a)The
Semigroupinstance for effects allows you to run two effects, one after the other, and then combine their results using the result type'sSemigroupinstance.(Monoid a) => Monoid (Effect a)If you have a
Monoid ainstance, thenmempty :: Effect ais defined aspure mempty.
Re-exports from Effect.Class
#MonadEffect Source
class (Monad m) <= MonadEffect m whereThe MonadEffect class captures those monads which support native effects.
Instances are provided for Effect itself, and the standard monad
transformers.
liftEffect can be used in any appropriate monad transformer stack to lift an
action of type Effect a into the monad.
Members
liftEffect :: forall a. Effect a -> m a
Instances
Re-exports from Effect.Class.Console
Re-exports from Effect.Exception
Re-exports from Effect.Uncurried
#runEffectFn9 Source
runEffectFn9 :: forall r i h g f e d c b a. EffectFn9 a b c d e f g h i r -> a -> b -> c -> d -> e -> f -> g -> h -> i -> Effect r#runEffectFn8 Source
runEffectFn8 :: forall r h g f e d c b a. EffectFn8 a b c d e f g h r -> a -> b -> c -> d -> e -> f -> g -> h -> Effect r#runEffectFn7 Source
runEffectFn7 :: forall r g f e d c b a. EffectFn7 a b c d e f g r -> a -> b -> c -> d -> e -> f -> g -> Effect r#runEffectFn6 Source
runEffectFn6 :: forall r f e d c b a. EffectFn6 a b c d e f r -> a -> b -> c -> d -> e -> f -> Effect r#runEffectFn5 Source
runEffectFn5 :: forall r e d c b a. EffectFn5 a b c d e r -> a -> b -> c -> d -> e -> Effect r#runEffectFn4 Source
runEffectFn4 :: forall r d c b a. EffectFn4 a b c d r -> a -> b -> c -> d -> Effect r#runEffectFn3 Source
runEffectFn3 :: forall r c b a. EffectFn3 a b c r -> a -> b -> c -> Effect r#runEffectFn2 Source
runEffectFn2 :: forall r b a. EffectFn2 a b r -> a -> b -> Effect r#runEffectFn10 Source
runEffectFn10 :: forall r j i h g f e d c b a. EffectFn10 a b c d e f g h i j r -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> Effect r#runEffectFn1 Source
runEffectFn1 :: forall r a. EffectFn1 a r -> a -> Effect r#mkEffectFn9 Source
mkEffectFn9 :: forall r i h g f e d c b a. (a -> b -> c -> d -> e -> f -> g -> h -> i -> Effect r) -> EffectFn9 a b c d e f g h i r#mkEffectFn8 Source
mkEffectFn8 :: forall r h g f e d c b a. (a -> b -> c -> d -> e -> f -> g -> h -> Effect r) -> EffectFn8 a b c d e f g h r#mkEffectFn7 Source
mkEffectFn7 :: forall r g f e d c b a. (a -> b -> c -> d -> e -> f -> g -> Effect r) -> EffectFn7 a b c d e f g r#mkEffectFn6 Source
mkEffectFn6 :: forall r f e d c b a. (a -> b -> c -> d -> e -> f -> Effect r) -> EffectFn6 a b c d e f r#mkEffectFn5 Source
mkEffectFn5 :: forall r e d c b a. (a -> b -> c -> d -> e -> Effect r) -> EffectFn5 a b c d e r#mkEffectFn4 Source
mkEffectFn4 :: forall r d c b a. (a -> b -> c -> d -> Effect r) -> EffectFn4 a b c d r#mkEffectFn3 Source
mkEffectFn3 :: forall r c b a. (a -> b -> c -> Effect r) -> EffectFn3 a b c r#mkEffectFn2 Source
mkEffectFn2 :: forall r b a. (a -> b -> Effect r) -> EffectFn2 a b r#mkEffectFn10 Source
mkEffectFn10 :: forall r j i h g f e d c b a. (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> Effect r) -> EffectFn10 a b c d e f g h i j r#mkEffectFn1 Source
mkEffectFn1 :: forall r a. (a -> Effect r) -> EffectFn1 a rRe-exports from Effect.Unsafe
#unsafePerformEffect Source
unsafePerformEffect :: forall a. Effect a -> aRun an effectful computation.
Note: use of this function can result in arbitrary side-effects.
Re-exports from MasonPrelude.Functor.Nested
#mmmapFlipped Source
mmmapFlipped :: forall h g f b a. Functor f => Functor g => Functor h => f (g (h a)) -> (a -> b) -> f (g (h b))#mmapFlipped Source
mmapFlipped :: forall g f b a. Functor f => Functor g => f (g a) -> (a -> b) -> f (g b)#(<$$$>) Source
Operator alias for MasonPrelude.Functor.Nested.mmap (left-associative / precedence 4)
#(<##>) Source
Operator alias for MasonPrelude.Functor.Nested.mmapFlipped (left-associative / precedence 1)
#(<###>) Source
Operator alias for MasonPrelude.Functor.Nested.mmmapFlipped (left-associative / precedence 1)
Re-exports from MasonPrelude.Parallel
Re-exports from PointFree
#composeThirdFlipped Source
composeThirdFlipped :: forall z y x b a. (z -> b) -> (x -> y -> b -> a) -> x -> y -> z -> a#composeThird Source
composeThird :: forall z y x b a. (x -> y -> b -> a) -> (z -> b) -> x -> y -> z -> a\f g x y z -> f x y (g z)
#composeSecondFlipped Source
composeSecondFlipped :: forall y x b a. (y -> b) -> (x -> b -> a) -> x -> y -> a#composeSecond Source
composeSecond :: forall y x b a. (x -> b -> a) -> (y -> b) -> x -> y -> a\f g x y -> f x (g y)
#composeFourthFlipped Source
composeFourthFlipped :: forall z y x w b a. (z -> b) -> (w -> x -> y -> b -> a) -> w -> x -> y -> z -> a#composeFourth Source
composeFourth :: forall z y x w b a. (w -> x -> y -> b -> a) -> (z -> b) -> w -> x -> y -> z -> a\f g w x y z -> f w x y (g z)
#compose4Flipped Source
compose4Flipped :: forall z y x w b a. (w -> x -> y -> z -> a) -> (a -> b) -> w -> x -> y -> z -> b#compose4 Source
compose4 :: forall z y x w b a. (a -> b) -> (w -> x -> y -> z -> a) -> w -> x -> y -> z -> b\f g w x y z -> f (g w x y z)
#compose3SecondFlipped Source
compose3SecondFlipped :: forall z y x w b a. (x -> y -> z -> b) -> (w -> b -> a) -> w -> x -> y -> z -> a#compose3Second Source
compose3Second :: forall z y x w b a. (w -> b -> a) -> (x -> y -> z -> b) -> w -> x -> y -> z -> a\f g w x y z -> f w (g x y z)
#compose3Flipped Source
compose3Flipped :: forall z y x b a. (x -> y -> z -> a) -> (a -> b) -> x -> y -> z -> b#compose3 Source
compose3 :: forall z y x b a. (a -> b) -> (x -> y -> z -> a) -> x -> y -> z -> b\f g x y z -> f (g x y z)
#compose2ThirdFlipped Source
compose2ThirdFlipped :: forall z y x w b a. (y -> z -> b) -> (w -> x -> b -> a) -> w -> x -> y -> z -> a#compose2Third Source
compose2Third :: forall z y x w b a. (w -> x -> b -> a) -> (y -> z -> b) -> w -> x -> y -> z -> a\f g w x y z -> f w x (g y z)
#compose2SecondFlipped Source
compose2SecondFlipped :: forall z y x b a. (y -> z -> b) -> (x -> b -> a) -> x -> y -> z -> a#compose2Second Source
compose2Second :: forall z y x b a. (x -> b -> a) -> (y -> z -> b) -> x -> y -> z -> a\f g x y z -> f x (g y z)
#compose2Flipped Source
compose2Flipped :: forall y x b a. (x -> y -> a) -> (a -> b) -> x -> y -> b#compose2 Source
compose2 :: forall y x b a. (a -> b) -> (x -> y -> a) -> x -> y -> b\f g x y -> f (g x y)
#applyThirdFlipped Source
applyThirdFlipped :: forall a z y x. x -> (y -> z -> x -> a) -> y -> z -> a#applyThird Source
applyThird :: forall a z y x. (y -> z -> x -> a) -> x -> y -> z -> a\f x y z -> f y z x
#applySecondFlipped Source
applySecondFlipped :: forall a y x. x -> (y -> x -> a) -> y -> a#applyFourthFlipped Source
applyFourthFlipped :: forall a z y x w. w -> (x -> y -> z -> w -> a) -> x -> y -> z -> a#applyFourth Source
applyFourth :: forall a z y x w. (x -> y -> z -> w -> a) -> w -> x -> y -> z -> a\f w x y z -> f x y z w
#(<.) Source
Operator alias for Control.Semigroupoid.compose (left-associative / precedence 9)
\f g x -> f (g x)
#(.>) Source
Operator alias for Control.Semigroupoid.composeFlipped (right-associative / precedence 9)
Re-exports from Prelude
#Ordering Source
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
Instances
#Applicative Source
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 identity) <*> 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 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
#Bind Source
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
#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 BooleanBooleanAlgebra Unit(BooleanAlgebra b) => BooleanAlgebra (a -> b)(RowToList row list, BooleanAlgebraRecord list row row) => BooleanAlgebra (Record row)
#Bounded Source
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
Instances
Bounded BooleanBounded IntThe
BoundedIntinstance hastop :: Intequal to 2^31 - 1, andbottom :: Intequal to -2^31, since these are the largest and smallest integers representable by twos-complement 32-bit integers, respectively.Bounded CharCharacters fall within the Unicode range.
Bounded OrderingBounded UnitBounded Number
#Category Source
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:
identity <<< p = p <<< identity = p
Members
identity :: 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
CommutativeRing IntCommutativeRing NumberCommutativeRing Unit(CommutativeRing b) => CommutativeRing (a -> b)(RowToList row list, CommutativeRingRecord list row row) => CommutativeRing (Record row)
#DivisionRing Source
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
#Eq Source
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
Instances
#EuclideanRing Source
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.
The EuclideanRing Int instance is one of the most commonly used
EuclideanRing instances and deserves a little more discussion. In
particular, there are a few different sensible law-abiding implementations
to choose from, with slightly different behaviour in the presence of
negative dividends or divisors. The most common definitions are "truncating"
division, where the result of a / b is rounded towards 0, and "Knuthian"
or "flooring" division, where the result of a / b is rounded towards
negative infinity. A slightly less common, but arguably more useful, option
is "Euclidean" division, which is defined so as to ensure that a `mod` b
is always nonnegative. With Euclidean division, a / b rounds towards
negative infinity if the divisor is positive, and towards positive infinity
if the divisor is negative. Note that all three definitions are identical if
we restrict our attention to nonnegative dividends and divisors.
In versions 1.x, 2.x, and 3.x of the Prelude, the EuclideanRing Int
instance used truncating division. As of 4.x, the EuclideanRing Int
instance uses Euclidean division. Additional functions quot and rem are
supplied if truncating division is desired.
Members
Instances
#Field Source
class (EuclideanRing a, DivisionRing a) <= Field a The Field class is for types that are (commutative) fields.
Mathematically, a field is a ring which is commutative and in which every
nonzero element has a multiplicative inverse; these conditions correspond
to the CommutativeRing and DivisionRing classes in PureScript
respectively. However, the Field class has EuclideanRing and
DivisionRing as superclasses, which seems like a stronger requirement
(since CommutativeRing is a superclass of EuclideanRing). In fact, it
is not stronger, since any type which has law-abiding CommutativeRing
and DivisionRing instances permits exactly one law-abiding
EuclideanRing instance. We use a EuclideanRing superclass here in
order to ensure that a Field constraint on a function permits you to use
div on that type, since div is a member of EuclideanRing.
This class has no laws or members of its own; it exists as a convenience, so a single constraint can be used when field-like behaviour is expected.
This module also defines a single Field instance for any type which has
both EuclideanRing and DivisionRing instances. Any other instance
would overlap with this instance, so no other Field instances should be
defined in libraries. Instead, simply define EuclideanRing and
DivisionRing instances, and this will permit your type to be used with a
Field constraint.
Instances
(EuclideanRing a, DivisionRing a) => Field a
#Functor Source
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 identity = identity - 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 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
Instances
HeytingAlgebra BooleanHeytingAlgebra Unit(HeytingAlgebra b) => HeytingAlgebra (a -> b)(RowToList row list, HeytingAlgebraRecord list row row) => HeytingAlgebra (Record row)
#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 - Applicative Superclass:
apply = ap
Instances
#Monoid Source
class (Semigroup m) <= Monoid m whereA Monoid is a Semigroup with a value mempty, which is both a
left and right unit for the associative operation <>:
- Left unit:
(mempty <> x) = x - Right unit:
(x <> mempty) = x
Monoids are commonly used as the result of fold operations, where
<> is used to combine individual results, and mempty gives the result
of folding an empty collection of elements.
Members
mempty :: m
Instances
#Ord Source
#Ring Source
#Semigroup Source
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
#Semigroupoid Source
class Semigroupoid a whereA Semigroupoid is similar to a Category but does not
require an identity element identity, 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
#Semiring Source
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
Instances
#Show Source
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
Instances
#when Source
when :: forall m. Applicative m => Boolean -> m Unit -> m UnitPerform an applicative action when a condition is true.
#void Source
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)
#unless Source
unless :: forall m. Applicative m => Boolean -> m Unit -> m UnitPerform an applicative action unless a condition is true.
#liftM1 Source
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 Source
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 Source
lcm :: forall a. Eq a => EuclideanRing a => a -> a -> aThe least common multiple of two values.
#gcd Source
gcd :: forall a. Eq a => EuclideanRing a => a -> a -> aThe greatest common divisor of two values.
#flip Source
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 Source
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 -> Array 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 -> aReturns its first argument and ignores its second.
const 1 "hello" = 1
#(>>>) Source
Operator alias for Control.Semigroupoid.composeFlipped (right-associative / precedence 9)
#(<=<) Source
Operator alias for Control.Bind.composeKleisliFlipped (right-associative / precedence 1)
#($) Source
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
#(#) Source
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 (~>) Source
Operator alias for Data.NaturalTransformation.NaturalTransformation (right-associative / precedence 4)
Re-exports from Unsafe.Coerce
#unsafeCoerce Source
unsafeCoerce :: forall b a. a -> bA highly unsafe function, which can be used to persuade the type system that any type is the same as any other type. When using this function, it is your (that is, the caller's) responsibility to ensure that the underlying representation for both types is the same.
One application for this function is to avoid doing work that you know is a
no-op because of newtypes. For example, if you have an Array (Conj a) and you
want an Array (Disj a), you could do Data.Array.map (runConj >>> Disj), but
this performs an unnecessary traversal. unsafeCoerce accomplishes the same
for free.
It is highly recommended to define specializations of this function rather than using it as-is. For example:
mapConjToDisj :: forall a. Array (Conj a) -> Array (Disj a)
mapConjToDisj = unsafeCoerce
This way, you won't have any nasty surprises due to the inferred type being different to what you expected.
The
Functorinstance allows functions to transform the contents of aRightwith the<$>operator:Leftvalues are untouched: