MCPrelude
This MCPrelude is a modified, PureScript version of the Haskell MCPrelude from the original Monad Challenges, which is a modified version of the Haskell Prelude designed specifically for The Monad Challenges.
#greekDataA
#greekDataB
#firstNames
#Triple
Re-exports from Data.Array
#zipWith
zipWith :: forall a b c. (a -> b -> c) -> Array a -> Array b -> Array cApply a function to pairs of elements at the same index in two arrays, collecting the results in a new array.
If one array is longer, elements will be discarded from the longer array.
For example
zipWith (*) [1, 2, 3] [4, 5, 6, 7] == [4, 10, 18]
#zip
#takeWhile
#take
#span
span :: forall a. (a -> Boolean) -> Array a -> { init :: Array a, rest :: Array a }Split an array into two parts:
- the longest initial subarray for which all elements satisfy the specified predicate
- the remaining elements
span (\n -> n % 2 == 1) [1,3,2,4,5] == { init: [1,3], rest: [2,4,5] }
Running time: O(n).
#snoc
#replicate
#range
#length
#filter
#dropWhile
#drop
#cons
#concatMap
#concat
#(:)
Operator alias for Data.Array.cons (right-associative / precedence 6)
An infix alias for cons.
1 : [2, 3, 4] = [1, 2, 3, 4]
Note, the running time of this function is O(n).
#(..)
Operator alias for Data.Array.range (non-associative / precedence 8)
An infix synonym for range.
2 .. 5 = [2, 3, 4, 5]
Re-exports from Data.Foldable
#sum
#product
#or
or :: forall a f. 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.
#notElem
#elem
#any
any :: forall a b f. 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 a f. 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 a b f. 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.Int
#toNumber
Re-exports from Data.String.CodeUnits
#fromCharArray
fromCharArray :: Array Char -> StringConverts an array of characters into a string.
fromCharArray ['H', 'e', 'l', 'l', 'o'] == "Hello"
Re-exports from Data.String.Utils
#words
#lines
Re-exports from Data.Traversable
#scanr
scanr :: forall a b f. 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] = [6,5,3]
scanr (flip (-)) 10 [1,2,3] = [4,5,7]
#scanl
scanl :: forall a b f. 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]
Re-exports from Data.Tuple
#Tuple
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)(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 Prelude
#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
Instances
#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
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
#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
Instances
#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.
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
#Ord
#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
Instances
#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
Instances
#conj
conj :: forall a. HeytingAlgebra a => a -> a -> a#disj
disj :: forall a. HeytingAlgebra a => a -> a -> a#not
not :: forall a. HeytingAlgebra a => a -> a#otherwise
#notEq
#min
#max
#lcm
lcm :: forall a. Eq a => EuclideanRing a => a -> a -> aThe least common multiple of two values.
#gcd
gcd :: forall a. Eq a => EuclideanRing a => a -> a -> aThe greatest common divisor of two values.
#flip
flip :: forall a b c. (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
#const
const :: forall a b. a -> b -> aReturns its first argument and ignores its second.
const 1 "hello" = 1
#comparing
#(||)
Operator alias for Data.HeytingAlgebra.disj (right-associative / precedence 2)
#(>>>)
Operator alias for Control.Semigroupoid.composeFlipped (right-associative / precedence 9)
#(>=)
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 Data.Semigroup.append (right-associative / precedence 5)
#(<=)
Operator alias for Data.Ord.lessThanOrEq (left-associative / precedence 4)
#(<<<)
Operator alias for Control.Semigroupoid.compose (right-associative / precedence 9)
#(<$>)
Operator alias for Data.Functor.map (left-associative / precedence 4)
#(<)
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 Data.Semiring.mul (left-associative / precedence 7)
#(&&)
Operator alias for Data.HeytingAlgebra.conj (right-associative / precedence 3)
#($)
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
Modules
- Control.Alt
- Control.Alternative
- Control.Applicative
- Control.Apply
- Control.Biapplicative
- Control.Biapply
- Control.Bind
- Control.Category
- Control.Comonad
- Control.Extend
- Control.Lazy
- Control.Monad
- Control.Monad.Gen
- Control.Monad.Gen.Class
- Control.Monad.Gen.Common
- Control.Monad.Rec.Class
- Control.Monad.ST
- Control.Monad.ST.Class
- Control.Monad.ST.Global
- Control.Monad.ST.Internal
- Control.Monad.ST.Ref
- Control.MonadPlus
- Control.MonadZero
- Control.Plus
- Control.Semigroupoid
- Data.Array
- Data.Array.NonEmpty
- Data.Array.NonEmpty.Internal
- Data.Array.Partial
- Data.Array.ST
- Data.Array.ST.Iterator
- Data.Array.ST.Partial
- Data.Bifoldable
- Data.Bifunctor
- Data.Bifunctor.Clown
- Data.Bifunctor.Flip
- Data.Bifunctor.Join
- Data.Bifunctor.Joker
- Data.Bifunctor.Product
- Data.Bifunctor.Wrap
- Data.Bitraversable
- Data.Boolean
- Data.BooleanAlgebra
- Data.Bounded
- Data.Char
- Data.Char.Gen
- Data.Char.Utils
- Data.CommutativeRing
- Data.Distributive
- Data.DivisionRing
- Data.Either
- Data.Either.Inject
- Data.Either.Nested
- Data.Enum
- Data.Enum.Gen
- Data.Eq
- Data.EuclideanRing
- Data.Field
- Data.Foldable
- Data.FoldableWithIndex
- Data.Function
- Data.Function.Uncurried
- Data.Functor
- Data.Functor.Invariant
- Data.FunctorWithIndex
- Data.HeytingAlgebra
- Data.Identity
- Data.Int
- Data.Int.Bits
- Data.Maybe
- Data.Maybe.First
- Data.Maybe.Last
- Data.Monoid
- Data.Monoid.Additive
- Data.Monoid.Alternate
- Data.Monoid.Conj
- Data.Monoid.Disj
- Data.Monoid.Dual
- Data.Monoid.Endo
- Data.Monoid.Multiplicative
- Data.NaturalTransformation
- Data.Newtype
- Data.NonEmpty
- Data.Ord
- Data.Ord.Down
- Data.Ord.Max
- Data.Ord.Min
- Data.Ord.Unsafe
- Data.Ordering
- Data.Ring
- Data.Semigroup
- Data.Semigroup.First
- Data.Semigroup.Foldable
- Data.Semigroup.Last
- Data.Semigroup.Traversable
- Data.Semiring
- Data.Show
- Data.String
- Data.String.CaseInsensitive
- Data.String.CodePoints
- Data.String.CodeUnits
- Data.String.Common
- Data.String.Gen
- Data.String.NonEmpty
- Data.String.NonEmpty.CaseInsensitive
- Data.String.NonEmpty.CodePoints
- Data.String.NonEmpty.CodeUnits
- Data.String.NonEmpty.Internal
- Data.String.Pattern
- Data.String.Regex
- Data.String.Regex.Flags
- Data.String.Regex.Unsafe
- Data.String.Unsafe
- Data.String.Utils
- Data.Symbol
- Data.Traversable
- Data.Traversable.Accum
- Data.Traversable.Accum.Internal
- Data.TraversableWithIndex
- Data.Tuple
- Data.Tuple.Nested
- Data.Unfoldable
- Data.Unfoldable1
- Data.Unit
- Data.Void
- Effect
- Effect.Class
- Effect.Class.Console
- Effect.Console
- Effect.Ref
- Effect.Uncurried
- Effect.Unsafe
- Global
- Global.Unsafe
- MCPrelude
- Main
- Math
- PSCI.Support
- Partial
- Partial.Unsafe
- Prelude
- Prim
- Prim.Boolean
- Prim.Ordering
- Prim.Row
- Prim.RowList
- Prim.Symbol
- Prim.TypeError
- Record.Unsafe
- Type.Data.Row
- Type.Data.RowList
- Type.Equality
- Unsafe.Coerce
Allows
Tuples to be rendered as a string withshowwhenever there areShowinstances for both component types.