@@ -1,1551 +0,0 @@
9− , Semigroupoid, (<<<), (>>>)
11− , Functor, (<$>), (<#>), void
13− , Applicative, pure, liftA1
15− , Monad, return, liftM1, ap
16− , Semigroup, (<>), (++)
17− , Semiring, (+), zero, (*), one
18− , ModuloSemiring, (/), mod
23− , Ordering(..), Ord, compare, (<), (>), (<=), (>=)
24− , Bounded, top, bottom
25− , Lattice, sup, inf, (||), (&&)
27− , ComplementedLattice, not
28− , DistributiveLattice
33− -- | The `Unit` type has a single inhabitant, called `unit`. It represents
34− -- | values with no computational content.
36− -- | `Unit` is often used, wrapped in a monadic type constructor, as the
37− -- | return type of a computation where only
38− -- | the _effects_ are important.
39− newtype Unit = Unit {}
41− -- | `unit` is the sole inhabitant of the `Unit` type.
48− -- | Applies a function to its argument.
51− -- | length $ groupBy productCategory $ filter isInStock $ products
54− -- | is equivalent to:
57− -- | length (groupBy productCategory (filter isInStock products))
60− -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of
61− -- | left: `a $ b $ c $ d x = a $ (b $ (c $ (d $ x))) = a (b (c (d x)))`
62− ($) :: forall a b. (a -> b) -> a -> b
65− -- | Applies an argument to a function.
68− -- | products # filter isInStock # groupBy productCategory # length
71− -- | is equivalent to:
74− -- | length (groupBy productCategory (filter isInStock products))
77− -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of
78− -- | right: `x # a # b # c # d = (((x # a) # b) # c) # d = d (c (b (a x)))`
79− (#) :: forall a b. a -> (a -> b) -> b
82− -- | Flips the order of the arguments to a function of two arguments.
85− -- | flip const 1 2 = const 2 1 = 2
87− flip :: forall a b c. (a -> b -> c) -> b -> a -> c
90− -- | Returns its first argument and ignores its second.
93− -- | const 1 "hello" = 1
95− const :: forall a b. a -> b -> a
98− -- | This function returns its first argument, and can be used to assert type
99− -- | equalities. This can be useful when types are otherwise ambiguous.
102− -- | main = print $ [] `asTypeOf` [0]
105− -- | If instead, we had written `main = print []`, the type of the argument
106− -- | `[]` would have been ambiguous, resulting in a compile-time error.
107− asTypeOf :: forall a. a -> a -> a
110− -- | An alias for `true`, which can be useful in guard clauses:
113− -- | max x y | x >= y = x
114− -- | | otherwise = y
116− otherwise :: Boolean
119− -- | Attaches an element to the front of an array, creating a new array.
122− -- | cons 1 [2, 3, 4] = [1, 2, 3, 4]
125− -- | Note, the running time of this function is `O(n)`.
129− return function(l) {
130− return [e].concat(l);
133− """ :: forall a. a -> [a] -> [a]
137− -- | An infix alias for `cons`.
139− -- | Note, the running time of this function is `O(n)`.
140− (:) :: forall a. a -> [a] -> [a]
146− -- | A `Semigroupoid` is similar to a [`Category`](#category) but does not
147− -- | require an identity element `id`, just composable morphisms.
149− -- | `Semigroupoid`s must satisfy the following law:
151− -- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
153− -- | One example of a `Semigroupoid` is the function type constructor `(->)`,
154− -- | with `(<<<)` defined as function composition.
155− class Semigroupoid a where
156− (<<<) :: forall b c d. a c d -> a b c -> a b d
158− instance semigroupoidArr :: Semigroupoid (->) where
159− (<<<) f g x = f (g x)
161− -- | Forwards composition, or `(<<<)` with its arguments reversed.
162− (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
165− -- | `Category`s consist of objects and composable morphisms between them, and
166− -- | as such are [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids`
167− -- | must have an identity element.
169− -- | Instances must satisfy the following law in addition to the
170− -- | `Semigroupoid` law:
172− -- | - Identity: `id <<< p = p <<< id = p`
173− class (Semigroupoid a) <= Category a where
174− id :: forall t. a t t
176− instance categoryArr :: Category (->) where
182− -- | A `Functor` is a type constructor which supports a mapping operation
185− -- | `(<$>)` can be used to turn functions `a -> b` into functions
186− -- | `f a -> f b` whose argument and return types use the type constructor `f`
187− -- | to represent some computational context.
189− -- | Instances must satisfy the following laws:
191− -- | - Identity: `(<$>) id = id`
192− -- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
193− class Functor f where
194− (<$>) :: forall a b. (a -> b) -> f a -> f b
196− instance functorArr :: Functor ((->) r) where
199− -- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
202− -- | [1, 2, 3] <#> \n -> n * n
204− (<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
205− (<#>) fa f = f <$> fa
207− -- | The `void` function is used to ignore the type wrapped by a
208− -- | [`Functor`](#functor), replacing it with `Unit` and keeping only the type
209− -- | information provided by the type constructor itself.
211− -- | `void` is often useful when using `do` notation to change the return type
212− -- | of a monadic computation:
215− -- | main = forE 1 10 \n -> void do
219− void :: forall f a. (Functor f) => f a -> f Unit
220− void fa = const unit <$> fa
224− -- | The `Apply` class provides the `(<*>)` which is used to apply a function
225− -- | to an argument under a type constructor.
227− -- | `Apply` can be used to lift functions of two or more arguments to work on
228− -- | values wrapped with the type constructor `f`. It might also be understood
229− -- | in terms of the `lift2` function:
232− -- | lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
233− -- | lift2 f a b = f <$> a <*> b
236− -- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts
237− -- | the function application operator `($)` to arguments wrapped with the
238− -- | type constructor `f`.
240− -- | Instances must satisfy the following law in addition to the `Functor`
243− -- | - Associative composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
245− -- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
246− class (Functor f) <= Apply f where
247− (<*>) :: forall a b. f (a -> b) -> f a -> f b
249− instance applyArr :: Apply ((->) r) where
250− (<*>) f g x = f x (g x)
252− -- | The `Applicative` type class extends the [`Apply`](#apply) type class
253− -- | with a `pure` function, which can be used to create values of type `f a`
254− -- | from values of type `a`.
256− -- | Where [`Apply`](#apply) provides the ability to lift functions of two or
257− -- | more arguments to functions whose arguments are wrapped using `f`, and
258− -- | [`Functor`](#functor) provides the ability to lift functions of one
259− -- | argument, `pure` can be seen as the function which lifts functions of
260− -- | _zero_ arguments. That is, `Applicative` functors support a lifting
261− -- | operation for any number of function arguments.
263− -- | Instances must satisfy the following laws in addition to the `Apply`
266− -- | - Identity: `(pure id) <*> v = v`
267− -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
268− -- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
269− -- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
270− class (Apply f) <= Applicative f where
271− pure :: forall a. a -> f a
273− instance applicativeArr :: Applicative ((->) r) where
276− -- | `return` is an alias for `pure`.
277− return :: forall m a. (Applicative m) => a -> m a
280− -- | `liftA1` provides a default implementation of `(<$>)` for any
281− -- | [`Applicative`](#applicative) functor, without using `(<$>)` as provided
282− -- | by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass
285− -- | `liftA1` can therefore be used to write [`Functor`](#functor) instances
289− -- | instance functorF :: Functor F where
292− liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
293− liftA1 f a = pure f <*> a
297− -- | The `Bind` type class extends the [`Apply`](#apply) type class with a
298− -- | "bind" operation `(>>=)` which composes computations in sequence, using
299− -- | the return value of one computation to determine the next computation.
301− -- | The `>>=` operator can also be expressed using `do` notation, as follows:
304− -- | x >>= f = do y <- x
308− -- | where the function argument of `f` is given the name `y`.
310− -- | Instances must satisfy the following law in addition to the `Apply`
313− -- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
315− -- | Associativity tells us that we can regroup operations which use `do`
316− -- | notation so that we can unambiguously write, for example:
323− class (Apply m) <= Bind m where
324− (>>=) :: forall a b. m a -> (a -> m b) -> m b
326− instance bindArr :: Bind ((->) r) where
327− (>>=) m f x = f (m x) x
329− -- | The `Monad` type class combines the operations of the `Bind` and
330− -- | `Applicative` type classes. Therefore, `Monad` instances represent type
331− -- | constructors which support sequential composition, and also lifting of
332− -- | functions of arbitrary arity.
334− -- | Instances must satisfy the following laws in addition to the
335− -- | `Applicative` and `Bind` laws:
337− -- | - Left Identity: `pure x >>= f = f x`
338− -- | - Right Identity: `x >>= pure = x`
339− class (Applicative m, Bind m) <= Monad m
341− instance monadArr :: Monad ((->) r)
343− -- | `liftM1` provides a default implementation of `(<$>)` for any
344− -- | [`Monad`](#monad), without using `(<$>)` as provided by the
345− -- | [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
347− -- | `liftM1` can therefore be used to write [`Functor`](#functor) instances
351− -- | instance functorF :: Functor F where
354− liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
359− -- | `ap` provides a default implementation of `(<*>)` for any
360− -- | [`Monad`](#monad), without using `(<*>)` as provided by the
361− -- | [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
363− -- | `ap` can therefore be used to write [`Apply`](#apply) instances as
367− -- | instance applyF :: Apply F where
370− ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
379− -- | The `Semigroup` type class identifies an associative operation on a type.
381− -- | Instances are required to satisfy the following law:
383− -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
385− -- | One example of a `Semigroup` is `String`, with `(<>)` defined as string
387− class Semigroup a where
390− -- | `(++)` is an alias for `(<>)`.
391− (++) :: forall s. (Semigroup s) => s -> s -> s
394− instance semigroupString :: Semigroup String where
397− instance semigroupUnit :: Semigroup Unit where
400− instance semigroupArr :: (Semigroup s') => Semigroup (s -> s') where
401− (<>) f g = \x -> f x <> g x
403− instance semigroupOrdering :: Semigroup Ordering where
408− foreign import concatString
410− function concatString(s1) {
411− return function(s2) {
415− """ :: String -> String -> String
420− -- | The `Semiring` class is for types that support an addition and
421− -- | multiplication operation.
423− -- | Instances must satisfy the following laws:
425− -- | - Commutative monoid under addition:
426− -- | - Associativity: `(a + b) + c = a + (b + c)`
427− -- | - Identity: `zero + a = a + zero = a`
428− -- | - Commutative: `a + b = b + a`
429− -- | - Monoid under multiplication:
430− -- | - Associativity: `(a * b) * c = a * (b * c)`
431− -- | - Identity: `one * a = a * one = a`
432− -- | - Multiplication distributes over addition:
433− -- | - Left distributivity: `a * (b + c) = (a * b) + (a * c)`
434− -- | - Right distributivity: `(a + b) * c = (a * c) + (b * c)`
435− -- | - Annihiliation: `zero * a = a * zero = zero`
436− class Semiring a where
442− instance semiringNumber :: Semiring Number where
448− instance semiringUnit :: Semiring Unit where
456− -- | The `Ring` class is for types that support addition, multiplication,
457− -- | and subtraction operations.
459− -- | Instances must satisfy the following law in addition to the `Semiring`
462− -- | - Additive inverse: `a + (-a) = (-a) + a = zero`
463− class (Semiring a) <= Ring a where
466− instance ringNumber :: Ring Number where
469− instance ringUnit :: Ring Unit where
472− negate :: forall a. (Ring a) => a -> a
477− -- | The `ModuloSemiring` class is for types that support addition,
478− -- | multiplication, division, and modulo (division remainder) operations.
480− -- | Instances must satisfy the following law in addition to the `Semiring`
483− -- | - Remainder: `a / b * b + (a `mod` b) = a`
484− class (Semiring a) <= ModuloSemiring a where
488− instance moduloSemiringNumber :: ModuloSemiring Number where
492− instance moduloSemiringUnit :: ModuloSemiring Unit where
496− -- | A `Ring` where every nonzero element has a multiplicative inverse.
498− -- | Instances must satisfy the following law in addition to the `Ring` and
499− -- | `ModuloSemiring` laws:
501− -- | - Multiplicative inverse: `(one / x) * x = one`
503− -- | As a consequence of this ```a `mod` b = zero``` as no divide operation
504− -- | will have a remainder.
505− class (Ring a, ModuloSemiring a) <= DivisionRing a
507− instance divisionRingNumber :: DivisionRing Number
509− instance divisionRingUnit :: DivisionRing Unit
511− -- | The `Num` class is for types that are commutative fields.
513− -- | Instances must satisfy the following law in addition to the
514− -- | `DivisionRing` laws:
516− -- | - Commutative multiplication: `a * b = b * a`
517− class (DivisionRing a) <= Num a
519− instance numNumber :: Num Number
521− instance numUnit :: Num Unit
523− foreign import numAdd
525− function numAdd(n1) {
526− return function(n2) {
530− """ :: Number -> Number -> Number
532− foreign import numMul
534− function numMul(n1) {
535− return function(n2) {
539− """ :: Number -> Number -> Number
541− foreign import numDiv
543− function numDiv(n1) {
544− return function(n2) {
548− """ :: Number -> Number -> Number
550− foreign import numSub
552− function numSub(n1) {
553− return function(n2) {
557− """ :: Number -> Number -> Number
562− -- | The `Eq` type class represents types which support decidable equality.
564− -- | `Eq` instances should satisfy the following laws:
566− -- | - Reflexivity: `x == x = true`
567− -- | - Symmetry: `x == y = y == x`
568− -- | - Transitivity: if `x == y` and `y == z` then `x == z`
569− -- | - Negation: `x /= y = not (x == y)`
571− -- | `(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
573− (==) :: a -> a -> Boolean
574− (/=) :: a -> a -> Boolean
576− instance eqBoolean :: Eq Boolean where
580− instance eqNumber :: Eq Number where
584− instance eqString :: Eq String where
588− instance eqUnit :: Eq Unit where
592− instance eqArray :: (Eq a) => Eq [a] where
593− (==) = eqArrayImpl (==)
594− (/=) xs ys = not (xs == ys)
596− instance eqOrdering :: Eq Ordering where
601− (/=) x y = not (x == y)
603− foreign import refEq
605− function refEq(r1) {
606− return function(r2) {
610− """ :: forall a. a -> a -> Boolean
612− foreign import refIneq
614− function refIneq(r1) {
615− return function(r2) {
619− """ :: forall a. a -> a -> Boolean
621− foreign import eqArrayImpl
623− function eqArrayImpl(f) {
624− return function(xs) {
625− return function(ys) {
626− if (xs.length !== ys.length) return false;
627− for (var i = 0; i < xs.length; i++) {
628− if (!f(xs[i])(ys[i])) return false;
634− """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
636− -- | The `Ordering` data type represents the three possible outcomes of
637− -- | comparing two values:
639− -- | `LT` - The first value is _less than_ the second.
640− -- | `GT` - The first value is _greater than_ the second.
641− -- | `EQ` - The first value is _equal to_ or _incomparable to_ the second.
642− data Ordering = LT | GT | EQ
644− -- | The `Ord` type class represents types which support comparisons.
646− -- | `Ord` instances should satisfy the laws of _partially orderings_:
648− -- | - Reflexivity: `a <= a`
649− -- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
650− -- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
651− class (Eq a) <= Ord a where
652− compare :: a -> a -> Ordering
654− instance ordBoolean :: Ord Boolean where
655− compare false false = EQ
656− compare false true = LT
657− compare true true = EQ
658− compare true false = GT
660− instance ordNumber :: Ord Number where
661− compare = unsafeCompare
663− instance ordString :: Ord String where
664− compare = unsafeCompare
666− instance ordUnit :: Ord Unit where
669− instance ordArray :: (Ord a) => Ord [a] where
673− compare (x:xs) (y:ys) = case compare x y of
677− instance ordOrdering :: Ord Ordering where
691− -- | Test whether one value is _strictly less than_ another.
692− (<) :: forall a. (Ord a) => a -> a -> Boolean
693− (<) a1 a2 = case a1 `compare` a2 of
697− -- | Test whether one value is _strictly greater than_ another.
698− (>) :: forall a. (Ord a) => a -> a -> Boolean
699− (>) a1 a2 = case a1 `compare` a2 of
703− -- | Test whether one value is _non-strictly less than_ another.
704− (<=) :: forall a. (Ord a) => a -> a -> Boolean
705− (<=) a1 a2 = case a1 `compare` a2 of
709− -- | Test whether one value is _non-strictly greater than_ another.
710− (>=) :: forall a. (Ord a) => a -> a -> Boolean
711− (>=) a1 a2 = case a1 `compare` a2 of
715− unsafeCompare :: forall a. a -> a -> Ordering
716− unsafeCompare = unsafeCompareImpl LT EQ GT
718− foreign import unsafeCompareImpl
720− function unsafeCompareImpl(lt) {
721− return function(eq) {
722− return function(gt) {
723− return function(x) {
724− return function(y) {
725− return x < y ? lt : x > y ? gt : eq;
731− """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
733− -- | The `Bounded` type class represents types that are finite partially
736− -- | Instances should satisfy the following law in addition to the `Ord` laws:
738− -- | - Ordering: `bottom <= a <= top`
739− class (Ord a) <= Bounded a where
743− instance boundedBoolean :: Bounded Boolean where
747− instance boundedUnit :: Bounded Unit where
751− instance boundedOrdering :: Bounded Ordering where
755− -- | The `Lattice` type class represents types that are partially ordered
756− -- | sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`).
758− -- | Instances should satisfy the following laws in addition to the `Ord`
761− -- | - Associativity:
762− -- | - `a || (b || c) = (a || b) || c`
763− -- | - `a && (b && c) = (a && b) && c`
764− -- | - Commutativity:
765− -- | - `a || b = b || a`
766− -- | - `a && b = b && a`
768− -- | - `a || (a && b) = a`
769− -- | - `a && (a || b) = a`
773− class (Ord a) <= Lattice a where
777− instance latticeBoolean :: Lattice Boolean where
781− instance latticeUnit :: Lattice Unit where
788− -- | The `sup` operator.
789− (||) :: forall a. (Lattice a) => a -> a -> a
792− -- | The `inf` operator.
793− (&&) :: forall a. (Lattice a) => a -> a -> a
796− -- | The `BoundedLattice` type class represents types that are finite
799− -- | Instances should satisfy the following law in addition to the `Lattice`
800− -- | and `Bounded` laws:
803− -- | - `a || bottom = a`
804− -- | - `a && top = a`
805− -- | - Annihiliation:
806− -- | - `a || top = top`
807− -- | - `a && bottom = bottom`
808− class (Bounded a, Lattice a) <= BoundedLattice a
810− instance boundedLatticeBoolean :: BoundedLattice Boolean
812− instance boundedLatticeUnit :: BoundedLattice Unit
814− -- | The `ComplementedLattice` type class represents types that are lattices
815− -- | where every member is also uniquely complemented.
817− -- | Instances should satisfy the following law in addition to the
818− -- | `BoundedLattice` laws:
820− -- | - Complemented:
821− -- | - `not a || a == top`
822− -- | - `not a && a == bottom`
823− -- | - Double negation:
824− -- | - `not <<< not == id`
825− class (BoundedLattice a) <= ComplementedLattice a where
828− instance complementedLatticeBoolean :: ComplementedLattice Boolean where
831− instance complementedLatticeUnit :: ComplementedLattice Unit where
834− -- | The `DistributiveLattice` type class represents types that are lattices
835− -- | where the `&&` and `||` distribute over each other.
837− -- | Instances should satisfy the following law in addition to the `Lattice`
840− -- | - Distributivity: `x && (y || z) = (x && y) || (x && z)`
841− class (Lattice a) <= DistributiveLattice a
843− instance distributiveLatticeBoolean :: DistributiveLattice Boolean
845− instance distributiveLatticeUnit :: DistributiveLattice Unit
847− -- | The `BooleanAlgebra` type class represents types that are Boolean
848− -- | algebras, also known as Boolean lattices.
850− -- | Instances should satisfy the `ComplementedLattice` and
851− -- | `DistributiveLattice` laws.
852− class (ComplementedLattice a, DistributiveLattice a) <= BooleanAlgebra a
854− instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
856− instance booleanAlgebraUnit :: BooleanAlgebra Unit
858− foreign import boolOr
860− function boolOr(b1) {
861− return function(b2) {
865− """ :: Boolean -> Boolean -> Boolean
867− foreign import boolAnd
869− function boolAnd(b1) {
870− return function(b2) {
874− """ :: Boolean -> Boolean -> Boolean
876− foreign import boolNot
878− function boolNot(b) {
881− """ :: Boolean -> Boolean
883− -- | The `Show` type class represents those types which can be converted into
884− -- | a human-readable `String` representation.
886− -- | While not required, it is recommended that for any expression `x`, the
887− -- | string `show x` be executable PureScript code which evaluates to the same
888− -- | value as the expression `x`.
892− instance showBoolean :: Show Boolean where
894− show false = "false"
896− instance showNumber :: Show Number where
897− show = showNumberImpl
899− instance showString :: Show String where
900− show = showStringImpl
902− instance showUnit :: Show Unit where
905− instance showArray :: (Show a) => Show [a] where
906− show = showArrayImpl show
908− instance showOrdering :: Show Ordering where
913− foreign import showNumberImpl
915− function showNumberImpl(n) {
916− return n.toString();
918− """ :: Number -> String
920− foreign import showStringImpl
922− function showStringImpl(s) {
923− return JSON.stringify(s);
925− """ :: String -> String
927− foreign import showArrayImpl
929− function showArrayImpl(f) {
930− return function(xs) {
932− for (var i = 0, l = xs.length; i < l; i++) {
935− return '[' + ss.join(',') + ']';
938− """ :: forall a. (a -> String) -> [a] -> String
940−module Data.Function where
942− -- | The `on` function is used to change the domain of a binary operator.
944− -- | For example, we can create a function which compares two records based on the values of their `x` properties:
947− -- | compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
948− -- | compareX = compare `on` _.x
950− on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
951− on f g x y = g x `f` g y
953− -- | A function of zero arguments
954− foreign import data Fn0 :: * -> *
956− -- | A function of one argument
957− foreign import data Fn1 :: * -> * -> *
959− -- | A function of two arguments
960− foreign import data Fn2 :: * -> * -> * -> *
962− -- | A function of three arguments
963− foreign import data Fn3 :: * -> * -> * -> * -> *
965− -- | A function of four arguments
966− foreign import data Fn4 :: * -> * -> * -> * -> * -> *
968− -- | A function of five arguments
969− foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
971− -- | A function of six arguments
972− foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
974− -- | A function of seven arguments
975− foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
977− -- | A function of eight arguments
978− foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
980− -- | A function of nine arguments
981− foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
983− -- | A function of ten arguments
984− foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
986− -- | Create a function of no arguments
987− foreign import mkFn0
989− function mkFn0(fn) {
994− """ :: forall a. (Unit -> a) -> Fn0 a
996− -- | Create a function of one argument
997− foreign import mkFn1
999− function mkFn1(fn) {
1000− return function(a) {
1004− """ :: forall a b. (a -> b) -> Fn1 a b
1006− -- | Create a function of two arguments from a curried function
1007− foreign import mkFn2
1009− function mkFn2(fn) {
1010− return function(a, b) {
1014− """ :: forall a b c. (a -> b -> c) -> Fn2 a b c
1016− -- | Create a function of three arguments from a curried function
1017− foreign import mkFn3
1019− function mkFn3(fn) {
1020− return function(a, b, c) {
1021− return fn(a)(b)(c);
1024− """ :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
1026− -- | Create a function of four arguments from a curried function
1027− foreign import mkFn4
1029− function mkFn4(fn) {
1030− return function(a, b, c, d) {
1031− return fn(a)(b)(c)(d);
1034− """ :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
1036− -- | Create a function of five arguments from a curried function
1037− foreign import mkFn5
1039− function mkFn5(fn) {
1040− return function(a, b, c, d, e) {
1041− return fn(a)(b)(c)(d)(e);
1044− """ :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
1046− -- | Create a function of six arguments from a curried function
1047− foreign import mkFn6
1049− function mkFn6(fn) {
1050− return function(a, b, c, d, e, f) {
1051− return fn(a)(b)(c)(d)(e)(f);
1054− """ :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
1056− -- | Create a function of seven arguments from a curried function
1057− foreign import mkFn7
1059− function mkFn7(fn) {
1060− return function(a, b, c, d, e, f, g) {
1061− return fn(a)(b)(c)(d)(e)(f)(g);
1064− """ :: forall a b c d e f g h. (a -> b -> c -> d -> e -> f -> g -> h) -> Fn7 a b c d e f g h
1066− -- | Create a function of eight arguments from a curried function
1067− foreign import mkFn8
1069− function mkFn8(fn) {
1070− return function(a, b, c, d, e, f, g, h) {
1071− return fn(a)(b)(c)(d)(e)(f)(g)(h);
1074− """ :: forall a b c d e f g h i. (a -> b -> c -> d -> e -> f -> g -> h -> i) -> Fn8 a b c d e f g h i
1076− -- | Create a function of nine arguments from a curried function
1077− foreign import mkFn9
1079− function mkFn9(fn) {
1080− return function(a, b, c, d, e, f, g, h, i) {
1081− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i);
1084− """ :: forall a b c d e f g h i j. (a -> b -> c -> d -> e -> f -> g -> h -> i -> j) -> Fn9 a b c d e f g h i j
1086− -- | Create a function of ten arguments from a curried function
1087− foreign import mkFn10
1089− function mkFn10(fn) {
1090− return function(a, b, c, d, e, f, g, h, i, j) {
1091− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);
1094− """ :: forall a b c d e f g h i j k. (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k) -> Fn10 a b c d e f g h i j k
1096− -- | Apply a function of no arguments
1097− foreign import runFn0
1099− function runFn0(fn) {
1102− """ :: forall a. Fn0 a -> a
1104− -- | Apply a function of one argument
1105− foreign import runFn1
1107− function runFn1(fn) {
1108− return function(a) {
1112− """ :: forall a b. Fn1 a b -> a -> b
1114− -- | Apply a function of two arguments
1115− foreign import runFn2
1117− function runFn2(fn) {
1118− return function(a) {
1119− return function(b) {
1124− """ :: forall a b c. Fn2 a b c -> a -> b -> c
1126− -- | Apply a function of three arguments
1127− foreign import runFn3
1129− function runFn3(fn) {
1130− return function(a) {
1131− return function(b) {
1132− return function(c) {
1133− return fn(a, b, c);
1138− """ :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
1140− -- | Apply a function of four arguments
1141− foreign import runFn4
1143− function runFn4(fn) {
1144− return function(a) {
1145− return function(b) {
1146− return function(c) {
1147− return function(d) {
1148− return fn(a, b, c, d);
1154− """ :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
1156− -- | Apply a function of five arguments
1157− foreign import runFn5
1159− function runFn5(fn) {
1160− return function(a) {
1161− return function(b) {
1162− return function(c) {
1163− return function(d) {
1164− return function(e) {
1165− return fn(a, b, c, d, e);
1172− """ :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
1174− -- | Apply a function of six arguments
1175− foreign import runFn6
1177− function runFn6(fn) {
1178− return function(a) {
1179− return function(b) {
1180− return function(c) {
1181− return function(d) {
1182− return function(e) {
1183− return function(f) {
1184− return fn(a, b, c, d, e, f);
1192− """ :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
1194− -- | Apply a function of seven arguments
1195− foreign import runFn7
1197− function runFn7(fn) {
1198− return function(a) {
1199− return function(b) {
1200− return function(c) {
1201− return function(d) {
1202− return function(e) {
1203− return function(f) {
1204− return function(g) {
1205− return fn(a, b, c, d, e, f, g);
1214− """ :: forall a b c d e f g h. Fn7 a b c d e f g h -> a -> b -> c -> d -> e -> f -> g -> h
1216− -- | Apply a function of eight arguments
1217− foreign import runFn8
1219− function runFn8(fn) {
1220− return function(a) {
1221− return function(b) {
1222− return function(c) {
1223− return function(d) {
1224− return function(e) {
1225− return function(f) {
1226− return function(g) {
1227− return function(h) {
1228− return fn(a, b, c, d, e, f, g, h);
1238− """ :: forall a b c d e f g h i. Fn8 a b c d e f g h i -> a -> b -> c -> d -> e -> f -> g -> h -> i
1240− -- | Apply a function of nine arguments
1241− foreign import runFn9
1243− function runFn9(fn) {
1244− return function(a) {
1245− return function(b) {
1246− return function(c) {
1247− return function(d) {
1248− return function(e) {
1249− return function(f) {
1250− return function(g) {
1251− return function(h) {
1252− return function(i) {
1253− return fn(a, b, c, d, e, f, g, h, i);
1264− """ :: forall a b c d e f g h i j. Fn9 a b c d e f g h i j -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j
1266− -- | Apply a function of ten arguments
1267− foreign import runFn10
1269− function runFn10(fn) {
1270− return function(a) {
1271− return function(b) {
1272− return function(c) {
1273− return function(d) {
1274− return function(e) {
1275− return function(f) {
1276− return function(g) {
1277− return function(h) {
1278− return function(i) {
1279− return function(j) {
1280− return fn(a, b, c, d, e, f, g, h, i, j);
1292− """ :: forall a b c d e f g h i j k. Fn10 a b c d e f g h i j k -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k
1294−module Prelude.Unsafe where
1296− -- | Find the element of an array at the specified index.
1298− -- | Note: this function can cause unpredictable failure at runtime if the index is out-of-bounds.
1299− foreign import unsafeIndex
1301− function unsafeIndex(xs) {
1302− return function(n) {
1306− """ :: forall a. [a] -> Number -> a
1308−module Control.Monad.Eff
1312− , untilE, whileE, forE, foreachE
1315− -- | The `Eff` type constructor is used to represent _native_ effects.
1317− -- | See [Handling Native Effects with the Eff Monad](https://github.com/purescript/purescript/wiki/Handling-Native-Effects-with-the-Eff-Monad) for more details.
1319− -- | 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.
1320− foreign import data Eff :: # ! -> * -> *
1322− foreign import returnE
1324− function returnE(a) {
1325− return function() {
1329− """ :: forall e a. a -> Eff e a
1331− foreign import bindE
1333− function bindE(a) {
1334− return function(f) {
1335− return function() {
1340− """ :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
1342− -- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled.
1344− -- | The `runPure` function can be used to run pure computations and obtain their result.
1345− type Pure a = forall e. Eff e a
1347− -- | Run a pure computation and return its result.
1349− -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1350− -- | is to use parentheses instead.
1351− foreign import runPure
1353− function runPure(f) {
1356− """ :: forall a. Pure a -> a
1358− instance functorEff :: Functor (Eff e) where
1361− instance applyEff :: Apply (Eff e) where
1364− instance applicativeEff :: Applicative (Eff e) where
1367− instance bindEff :: Bind (Eff e) where
1370− instance monadEff :: Monad (Eff e)
1372− -- | Loop until a condition becomes `true`.
1374− -- | `untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
1375− -- | until its return value is `true`.
1376− foreign import untilE
1378− function untilE(f) {
1379− return function() {
1384− """ :: forall e. Eff e Boolean -> Eff e Unit
1386− -- | Loop while a condition is `true`.
1388− -- | `whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
1389− -- | `true`, it runs the effectful computation `m` and loops. If not, the computation ends.
1390− foreign import whileE
1392− function whileE(f) {
1393− return function(a) {
1394− return function() {
1402− """ :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
1404− -- | Loop over a consecutive collection of numbers.
1406− -- | `forE lo hi f` runs the computation returned by the function `f` for each of the inputs
1407− -- | between `lo` (inclusive) and `hi` (exclusive).
1408− foreign import forE
1410− function forE(lo) {
1411− return function(hi) {
1412− return function(f) {
1413− return function() {
1414− for (var i = lo; i < hi; i++) {
1421− """ :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
1423− -- | Loop over an array of values.
1425− -- | `foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`.
1426− foreign import foreachE
1428− function foreachE(as) {
1429− return function(f) {
1430− return function() {
1431− for (var i = 0; i < as.length; i++) {
1437− """ :: forall e a. [a] -> (a -> Eff e Unit) -> Eff e Unit
1439−module Control.Monad.Eff.Unsafe where
1441− import Control.Monad.Eff
1443− -- | Change the type of an effectful computation, allowing it to be run in another context.
1445− -- | Note: use of this function can result in arbitrary side-effects.
1446− foreign import unsafeInterleaveEff
1448− function unsafeInterleaveEff(f) {
1451− """ :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
1453−module Debug.Trace where
1455− import Control.Monad.Eff
1457− -- | The `Trace` effect represents those computations which write to the console.
1458− foreign import data Trace :: !
1460− -- | Write a `String` to the console.
1461− foreign import trace
1463− function trace(s) {
1464− return function() {
1469− """ :: forall r. String -> Eff (trace :: Trace | r) Unit
1471− -- | Write a value to the console, using its `Show` instance to produce a `String`.
1472− print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
1473− print o = trace (show o)
1475−module Control.Monad.ST where
1477− import Control.Monad.Eff
1479− -- | The `ST` effect represents _local mutation_, i.e. mutation which does not "escape" into the surrounding computation.
1481− -- | An `ST` computation is parameterized by a phantom type which is used to restrict the set of reference cells it is allowed to access.
1483− -- | The `runST` function can be used to handle the `ST` effect.
1484− foreign import data ST :: * -> !
1486− -- | The type `STRef s a` represents a mutable reference holding a value of type `a`, which can be used with the `ST s` effect.
1487− foreign import data STRef :: * -> * -> *
1489− -- | Create a new mutable reference.
1490− foreign import newSTRef
1492− function newSTRef(val) {
1493− return function() {
1494− return { value: val };
1497− """ :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1499− -- | Read the current value of a mutable reference.
1500− foreign import readSTRef
1502− function readSTRef(ref) {
1503− return function() {
1507− """ :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1509− -- | Modify the value of a mutable reference by applying a function to the current value.
1510− foreign import modifySTRef
1512− function modifySTRef(ref) {
1513− return function(f) {
1514− return function() {
1515− return ref.value = f(ref.value);
1519− """ :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1521− -- | Set the value of a mutable reference.
1522− foreign import writeSTRef
1524− function writeSTRef(ref) {
1525− return function(a) {
1526− return function() {
1527− return ref.value = a;
1531− """ :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1533− -- | Run an `ST` computation.
1535− -- | Note: the type of `runST` uses a rank-2 type to constrain the phantom type `s`, such that the computation must not leak any mutable references
1536− -- | to the surrounding computation.
1538− -- | It may cause problems to apply this function using the `$` operator. The recommended approach is to use parentheses instead.
1539− foreign import runST
1541− function runST(f) {
1544− """ :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1546− -- | A convenience function which combines `runST` with `runPure`, which can be used when the only required effect is `ST`.
1548− -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1549− -- | is to use parentheses instead.
1550− pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
1551− pureST st = runPure (runST st)