@@ -1,1487 +0,0 @@
7− , Semigroupoid, (<<<), (>>>)
12− , Functor, (<$>), (<#>), void
14− , Applicative, pure, liftA1
16− , Monad, return, liftM1, ap
17− , Semigroup, (<>), (++)
18− , Semiring, (+), zero, (*), one
19− , ModuloSemiring, (/), mod
25− , Ordering(..), Ord, compare, (<), (>), (<=), (>=)
26− , Bounded, top, bottom
27− , Lattice, sup, inf, (||), (&&)
29− , ComplementedLattice, not
30− , DistributiveLattice
34− -- | The `Unit` type has a single inhabitant, called `unit`. It represents values with no computational content.
36− -- | `Unit` is often used, wrapped in a monadic type constructor, as the return type of a computation where only
37− -- | the _effects_ are important.
38− newtype Unit = Unit {}
40− -- | `unit` is the sole inhabitant of the `Unit` type.
44− -- | An alias for `true`, which can be useful in guard clauses:
47− -- | max x y | x >= y = x
53− -- | Flips the order of the arguments to a function of two arguments.
56− -- | flip const 1 2 = const 2 1 = 2
58− flip :: forall a b c. (a -> b -> c) -> b -> a -> c
61− -- | Returns its first argument and ignores its second.
64− -- | const 1 "hello" = 1
66− const :: forall a b. a -> b -> a
69− -- | This function returns its first argument, and can be used to assert type equalities.
70− -- | This can be useful when types are otherwise ambiguous.
73− -- | main = print $ [] `asTypeOf` [0]
76− -- | If instead, we had written `main = print []`, the type of the argument `[]` would have
77− -- | been ambiguous, resulting in a compile-time error.
78− asTypeOf :: forall a. a -> a -> a
84− -- | A `Semigroupoid` is similar to a [`Category`](#category) but does not require an identity
85− -- | element `id`, just composable morphisms.
87− -- | `Semigroupoid`s should obey the following rule:
89− -- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
91− -- | One example of a `Semigroupoid` is the function type constructor `(->)`, with `(<<<)` defined
92− -- | as function composition.
93− class Semigroupoid a where
94− (<<<) :: forall b c d. a c d -> a b c -> a b d
96− instance semigroupoidArr :: Semigroupoid (->) where
97− (<<<) f g x = f (g x)
99− -- | Forwards composition, or `(<<<)` with its arguments reversed.
100− (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
103− -- | `Category`s consist of objects and composable morphisms between them, and as such are
104− -- | [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids` must have an identity element.
106− -- | `Category`s should obey the following rules.
108− -- | - Left Identity: `id <<< p = p`
109− -- | - Right Identity: `p <<< id = p`
110− class (Semigroupoid a) <= Category a where
111− id :: forall t. a t t
113− instance categoryArr :: Category (->) where
119− -- | Applies a function to its argument.
122− -- | length $ groupBy productCategory $ filter isInStock $ products
125− -- | is equivalent to
128− -- | length (groupBy productCategory (filter isInStock products))
131− -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
132− -- | `a $ b $ c $ d x` = `a $ (b $ (c $ (d $ x)))` = `a (b (c (d x)))`
133− ($) :: forall a b. (a -> b) -> a -> b
136− -- | Applies an argument to a function.
139− -- | products # filter isInStock # groupBy productCategory # length
142− -- | is equivalent to
145− -- | length (groupBy productCategory (filter isInStock products))
148− -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
149− -- | `x # a # b # c # d` = `(((x # a) # b) # c) # d` = `d (c (b (a x)))`
150− (#) :: forall a b. a -> (a -> b) -> b
155− -- | An infix alias for `cons`.
157− -- | Note, the running time of this function is `O(n)`.
158− (:) :: forall a. a -> [a] -> [a]
161− -- | Attaches an element to the front of an array, creating a new array.
164− -- | cons 1 [2, 3, 4] = [1, 2, 3, 4]
167− -- | Note, the running time of this function is `O(n)`.
171− return function(l) {
172− return [e].concat(l);
175− """ :: forall a. a -> [a] -> [a]
177− -- | The `Show` type class represents those types which can be converted into a human-readable `String` representation.
179− -- | While not required, it is recommended that for any expression `x`, the string `show x` be executable PureScript code
180− -- | which evaluates to the same value as the expression `x`.
184− instance showBoolean :: Show Boolean where
186− show false = "false"
188− instance showNumber :: Show Number where
189− show = showNumberImpl
191− instance showString :: Show String where
192− show = showStringImpl
194− instance showUnit :: Show Unit where
197− instance showArray :: (Show a) => Show [a] where
198− show = showArrayImpl show
200− instance showOrdering :: Show Ordering where
205− foreign import showNumberImpl
207− function showNumberImpl(n) {
208− return n.toString();
210− """ :: Number -> String
212− foreign import showStringImpl
214− function showStringImpl(s) {
215− return JSON.stringify(s);
217− """ :: String -> String
219− foreign import showArrayImpl
221− function showArrayImpl(f) {
222− return function(xs) {
224− for (var i = 0, l = xs.length; i < l; i++) {
227− return '[' + ss.join(',') + ']';
230− """ :: forall a. (a -> String) -> [a] -> String
235− -- | A `Functor` is a type constructor which supports a mapping operation `(<$>)`.
237− -- | `(<$>)` can be used to turn functions `a -> b` into functions `f a -> f b` whose argument and return
238− -- | types use the type constructor `f` to represent some computational context.
240− -- | `Functor` instances should satisfy the following laws:
242− -- | - Identity: `(<$>) id = id`
243− -- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
244− class Functor f where
245− (<$>) :: forall a b. (a -> b) -> f a -> f b
247− instance functorArr :: Functor ((->) r) where
250− -- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
253− -- | [1, 2, 3] <#> \n -> n * n
255− (<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
256− (<#>) fa f = f <$> fa
258− -- | The `void` function is used to ignore the type wrapped by a [`Functor`](#functor), replacing it with `Unit` and
259− -- | keeping only the type information provided by the type constructor itself.
261− -- | `void` is often useful when using `do` notation to change the return type of a monadic computation:
264− -- | main = forE 1 10 \n -> void do
268− void :: forall f a. (Functor f) => f a -> f Unit
269− void fa = const unit <$> fa
273− -- | The `Apply` class provides the `(<*>)` which is used to apply a function to an argument under a type constructor.
275− -- | `Apply` can be used to lift functions of two or more arguments to work on values wrapped with the type constructor `f`.
276− -- | It might also be understood in terms of the `lift2` function:
279− -- | lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
280− -- | lift2 f a b = f <$> a <*> b
283− -- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts the function application operator `($)` to arguments
284− -- | wrapped with the type constructor `f`.
286− -- | `Apply` instances should satisfy the following law:
288− -- | - Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
290− -- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
291− class (Functor f) <= Apply f where
292− (<*>) :: forall a b. f (a -> b) -> f a -> f b
294− instance applyArr :: Apply ((->) r) where
295− (<*>) f g x = f x (g x)
297− -- | The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
298− -- | create values of type `f a` from values of type `a`.
300− -- | Where [`Apply`](#apply) provides the ability to lift functions of two or more arguments to functions whose arguments are wrapped using `f`,
301− -- | and [`Functor`](#functor) provides the ability to lift functions of one argument, `pure` can be seen as the function which lifts functions of
302− -- | _zero_ arguments. That is, `Applicative` functors support a lifting operation for any number of function arguments.
304− -- | `Applicative` instances should satisfy the following laws:
306− -- | - Identity: `(pure id) <*> v = v`
307− -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
308− -- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
309− -- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
310− class (Apply f) <= Applicative f where
311− pure :: forall a. a -> f a
313− instance applicativeArr :: Applicative ((->) r) where
316− -- | `return` is an alias for `pure`.
317− return :: forall m a. (Applicative m) => a -> m a
320− -- | `liftA1` provides a default implementation of `(<$>)` for any [`Applicative`](#applicative) functor,
321− -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass relationship.
323− -- | `liftA1` can therefore be used to write [`Functor`](#functor) instances as follows:
326− -- | instance functorF :: Functor F where
329− liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
330− liftA1 f a = pure f <*> a
334− -- | The `Bind` type class extends the [`Apply`](#apply) type class with a "bind" operation `(>>=)` which composes computations
335− -- | in sequence, using the return value of one computation to determine the next computation.
337− -- | The `>>=` operator can also be expressed using `do` notation, as follows:
340− -- | x >>= f = do y <- x
344− -- | where the function argument of `f` is given the name `y`.
346− -- | `Bind` instances should satisfy the following law:
348− -- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
350− -- | Or, expressed using `do` notation:
352− -- | - Associativity: `do { z <- do { y <- x ; f y } ; g z } = do { k <- x ; do { y <- f k ; g y } }`
354− -- | Associativity tells us that we can regroup operations which use do-notation, so that we can unambiguously write, for example:
361− class (Apply m) <= Bind m where
362− (>>=) :: forall a b. m a -> (a -> m b) -> m b
364− instance bindArr :: Bind ((->) r) where
365− (>>=) m f x = f (m x) x
367− -- | The `Monad` type class combines the operations of the `Bind` and `Applicative` type classes. Therefore, `Monad` instances
368− -- | represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
370− -- | `Monad` instances should satisfy the following laws:
372− -- | - Left Identity: `pure x >>= f = f x`
373− -- | - Right Identity: `x >>= pure = x`
375− -- | Or, expressed using `do` notation:
377− -- | - Left Identity: `do { y <- pure x ; f y } = f x`
378− -- | - Right Identity: `do { y <- x ; pure y } = x`
379− class (Applicative m, Bind m) <= Monad m
381− instance monadArr :: Monad ((->) r)
383− -- | `liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
384− -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
386− -- | `liftM1` can therefore be used to write [`Functor`](#functor) instances as follows:
389− -- | instance functorF :: Functor F where
392− liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
397− -- | `ap` provides a default implementation of `(<*>)` for any [`Monad`](#monad),
398− -- | without using `(<*>)` as provided by the [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
400− -- | `ap` can therefore be used to write [`Apply`](#apply) instances as follows:
403− -- | instance applyF :: Apply F where
406− ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
415− -- | The `Semigroup` type class identifies an associative operation on a type.
417− -- | `Semigroup` instances are required to satisfy the following law:
419− -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
421− -- | For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
422− class Semigroup a where
425− -- | `(++)` is an alias for `(<>)`.
426− (++) :: forall s. (Semigroup s) => s -> s -> s
429− instance semigroupString :: Semigroup String where
432− instance semigroupUnit :: Semigroup Unit where
435− instance semigroupArr :: (Semigroup s') => Semigroup (s -> s') where
436− (<>) f g = \x -> f x <> g x
438− instance semigroupOrdering :: Semigroup Ordering where
443− foreign import concatString
445− function concatString(s1) {
446− return function(s2) {
450− """ :: String -> String -> String
455− -- | Addition and multiplication, satisfying the following laws:
457− -- | - `a` is a commutative monoid under addition
458− -- | - `a` is a monoid under multiplication
459− -- | - multiplication distributes over addition
460− -- | - multiplication by `zero` annihilates `a`
461− class Semiring a where
467− instance semiringNumber :: Semiring Number where
473− instance semiringUnit :: Semiring Unit where
481− -- | Addition, multiplication, modulo operation and division, satisfying:
483− -- | - ```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
498− -- | Addition, multiplication, and subtraction.
500− -- | Has the same laws as `Semiring` but additionally satisfying:
502− -- | - `a` is an abelian group under addition
503− class (Semiring a) <= Ring a where
506− instance ringNumber :: Ring Number where
509− instance ringUnit :: Ring Unit where
512− negate :: forall a. (Ring a) => a -> a
515− -- | Ring where every nonzero element has a multiplicative inverse so that:
517− -- | - ```a `mod` b = zero```
518− class (Ring a, ModuloSemiring a) <= DivisionRing a
520− instance divisionRingNumber :: DivisionRing Number
522− instance divisionRingUnit :: DivisionRing Unit
524− -- | A commutative field
525− class (DivisionRing a) <= Num a
527− instance numNumber :: Num Number
529− instance numUnit :: Num Unit
534− foreign import numAdd
536− function numAdd(n1) {
537− return function(n2) {
541− """ :: Number -> Number -> Number
543− foreign import numMul
545− function numMul(n1) {
546− return function(n2) {
550− """ :: Number -> Number -> Number
552− foreign import numDiv
554− function numDiv(n1) {
555− return function(n2) {
559− """ :: Number -> Number -> Number
561− foreign import numSub
563− function numSub(n1) {
564− return function(n2) {
568− """ :: Number -> Number -> Number
570− foreign import numMod
572− function numMod(n1) {
573− return function(n2) {
577− """ :: Number -> Number -> Number
582− -- | The `Eq` type class represents types which support decidable equality.
584− -- | `Eq` instances should satisfy the following laws:
586− -- | - Reflexivity: `x == x = true`
587− -- | - Symmetry: `x == y = y == x`
588− -- | - Transitivity: if `x == y` and `y == z` then `x == z`
589− -- | - Negation: `x /= y = not (x == y)`
591− -- | `(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
593− (==) :: a -> a -> Boolean
594− (/=) :: a -> a -> Boolean
596− instance eqBoolean :: Eq Boolean where
600− instance eqNumber :: Eq Number where
604− instance eqString :: Eq String where
608− instance eqUnit :: Eq Unit where
612− instance eqArray :: (Eq a) => Eq [a] where
613− (==) = eqArrayImpl (==)
614− (/=) xs ys = not (xs == ys)
616− foreign import refEq
618− function refEq(r1) {
619− return function(r2) {
623− """ :: forall a. a -> a -> Boolean
625− foreign import refIneq
627− function refIneq(r1) {
628− return function(r2) {
632− """ :: forall a. a -> a -> Boolean
634− foreign import eqArrayImpl
636− function eqArrayImpl(f) {
637− return function(xs) {
638− return function(ys) {
639− if (xs.length !== ys.length) return false;
640− for (var i = 0; i < xs.length; i++) {
641− if (!f(xs[i])(ys[i])) return false;
647− """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
649− -- | The `Ordering` data type represents the three possible outcomes of comparing two values:
651− -- | `LT` - The first value is _less than_ the second.
652− -- | `GT` - The first value is _greater than_ the second.
653− -- | `EQ` - The first value is _equal to_ or _incomparable to_ the second.
654− data Ordering = LT | GT | EQ
656− -- | The `Ord` type class represents types which support comparisons.
658− -- | `Ord` instances should satisfy the laws of _partially orderings_:
660− -- | - Reflexivity: `a <= a`
661− -- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
662− -- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
663− class (Eq a) <= Ord a where
664− compare :: a -> a -> Ordering
666− instance ordBoolean :: Ord Boolean where
667− compare false false = EQ
668− compare false true = LT
669− compare true true = EQ
670− compare true false = GT
672− instance ordNumber :: Ord Number where
673− compare = unsafeCompare
675− instance ordString :: Ord String where
676− compare = unsafeCompare
678− instance ordUnit :: Ord Unit where
681− instance ordArray :: (Ord a) => Ord [a] where
685− compare (x:xs) (y:ys) = case compare x y of
689− instance eqOrdering :: Eq Ordering where
694− (/=) x y = not (x == y)
701− -- | Test whether one value is _strictly less than_ another.
702− (<) :: forall a. (Ord a) => a -> a -> Boolean
703− (<) a1 a2 = case a1 `compare` a2 of
707− -- | Test whether one value is _strictly greater than_ another.
708− (>) :: forall a. (Ord a) => a -> a -> Boolean
709− (>) a1 a2 = case a1 `compare` a2 of
713− -- | Test whether one value is _non-strictly less than_ another.
714− (<=) :: forall a. (Ord a) => a -> a -> Boolean
715− (<=) a1 a2 = case a1 `compare` a2 of
719− -- | Test whether one value is _non-strictly greater than_ another.
720− (>=) :: forall a. (Ord a) => a -> a -> Boolean
721− (>=) a1 a2 = case a1 `compare` a2 of
725− unsafeCompare :: forall a. a -> a -> Ordering
726− unsafeCompare = unsafeCompareImpl LT EQ GT
728− foreign import unsafeCompareImpl
730− function unsafeCompareImpl(lt) {
731− return function(eq) {
732− return function(gt) {
733− return function(x) {
734− return function(y) {
735− return x < y ? lt : x > y ? gt : eq;
741− """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
743− -- | The `Bounded` type class represents types that are finite partially
746− -- | Instances should satisfy the following law in addition to the `Ord` laws:
748− -- | - Ordering: `bottom <= a <= top`
749− class (Ord a) <= Bounded a where
753− instance boundedBoolean :: Bounded Boolean where
757− instance boundedUnit :: Bounded Unit where
761− -- | The `Lattice` type class represents types that are partially ordered
762− -- | sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`).
764− -- | Instances should satisfy the following laws in addition to the `Ord`
767− -- | - Associativity:
768− -- | - `a || (b || c) = (a || b) || c`
769− -- | - `a && (b && c) = (a && b) && c`
770− -- | - Commutativity:
771− -- | - `a || b = b || a`
772− -- | - `a && b = b && a`
774− -- | - `a || (a && b) = a`
775− -- | - `a && (a || b) = a`
779− class (Ord a) <= Lattice a where
783− instance latticeBoolean :: Lattice Boolean where
790− -- | The `sup` operator.
791− (||) :: forall a. (Lattice a) => a -> a -> a
794− -- | The `inf` operator.
795− (&&) :: forall a. (Lattice a) => a -> a -> a
798− -- | The `BoundedLattice` type class represents types that are finite
801− -- | Instances should satisfy the following law in addition to the `Lattice`
802− -- | and `Bounded` laws:
805− -- | - `a || bottom = a`
806− -- | - `a && top = a`
807− -- | - Annihiliation:
808− -- | - `a || top = top`
809− -- | - `a && bottom = bottom`
810− class (Bounded a, Lattice a) <= BoundedLattice a
812− instance boundedLatticeBoolean :: BoundedLattice Boolean
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− -- | The `DistributiveLattice` type class represents types that are lattices
832− -- | where the `&&` and `||` distribute over each other.
834− -- | Instances should satisfy the following law in addition to the `Lattice`
837− -- | - Distributivity: `x && (y || z) = (x && y) || (x && z)`
838− class (Lattice a) <= DistributiveLattice a
840− instance distributiveLatticeBoolean :: DistributiveLattice Boolean
842− -- | The `BooleanAlgebra` type class represents types that are Boolean
843− -- | algebras, also known as Boolean lattices.
845− -- | Instances should satisfy the `ComplementedLattice` and
846− -- | `DistributiveLattice` laws.
847− class (ComplementedLattice a, DistributiveLattice a) <= BooleanAlgebra a
849− instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
851− foreign import boolOr
853− function boolOr(b1) {
854− return function(b2) {
858− """ :: Boolean -> Boolean -> Boolean
860− foreign import boolAnd
862− function boolAnd(b1) {
863− return function(b2) {
867− """ :: Boolean -> Boolean -> Boolean
869− foreign import boolNot
871− function boolNot(b) {
874− """ :: Boolean -> Boolean
876−module Data.Function where
878− -- | The `on` function is used to change the domain of a binary operator.
880− -- | For example, we can create a function which compares two records based on the values of their `x` properties:
883− -- | compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
884− -- | compareX = compare `on` _.x
886− on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
887− on f g x y = g x `f` g y
889− -- | A function of zero arguments
890− foreign import data Fn0 :: * -> *
892− -- | A function of one argument
893− foreign import data Fn1 :: * -> * -> *
895− -- | A function of two arguments
896− foreign import data Fn2 :: * -> * -> * -> *
898− -- | A function of three arguments
899− foreign import data Fn3 :: * -> * -> * -> * -> *
901− -- | A function of four arguments
902− foreign import data Fn4 :: * -> * -> * -> * -> * -> *
904− -- | A function of five arguments
905− foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
907− -- | A function of six arguments
908− foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
910− -- | A function of seven arguments
911− foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
913− -- | A function of eight arguments
914− foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
916− -- | A function of nine arguments
917− foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
919− -- | A function of ten arguments
920− foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
922− -- | Create a function of no arguments
923− foreign import mkFn0
925− function mkFn0(fn) {
930− """ :: forall a. (Unit -> a) -> Fn0 a
932− -- | Create a function of one argument
933− foreign import mkFn1
935− function mkFn1(fn) {
936− return function(a) {
940− """ :: forall a b. (a -> b) -> Fn1 a b
942− -- | Create a function of two arguments from a curried function
943− foreign import mkFn2
945− function mkFn2(fn) {
946− return function(a, b) {
950− """ :: forall a b c. (a -> b -> c) -> Fn2 a b c
952− -- | Create a function of three arguments from a curried function
953− foreign import mkFn3
955− function mkFn3(fn) {
956− return function(a, b, c) {
960− """ :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
962− -- | Create a function of four arguments from a curried function
963− foreign import mkFn4
965− function mkFn4(fn) {
966− return function(a, b, c, d) {
967− return fn(a)(b)(c)(d);
970− """ :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
972− -- | Create a function of five arguments from a curried function
973− foreign import mkFn5
975− function mkFn5(fn) {
976− return function(a, b, c, d, e) {
977− return fn(a)(b)(c)(d)(e);
980− """ :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
982− -- | Create a function of six arguments from a curried function
983− foreign import mkFn6
985− function mkFn6(fn) {
986− return function(a, b, c, d, e, f) {
987− return fn(a)(b)(c)(d)(e)(f);
990− """ :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
992− -- | Create a function of seven arguments from a curried function
993− foreign import mkFn7
995− function mkFn7(fn) {
996− return function(a, b, c, d, e, f, g) {
997− return fn(a)(b)(c)(d)(e)(f)(g);
1000− """ :: 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
1002− -- | Create a function of eight arguments from a curried function
1003− foreign import mkFn8
1005− function mkFn8(fn) {
1006− return function(a, b, c, d, e, f, g, h) {
1007− return fn(a)(b)(c)(d)(e)(f)(g)(h);
1010− """ :: 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
1012− -- | Create a function of nine arguments from a curried function
1013− foreign import mkFn9
1015− function mkFn9(fn) {
1016− return function(a, b, c, d, e, f, g, h, i) {
1017− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i);
1020− """ :: 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
1022− -- | Create a function of ten arguments from a curried function
1023− foreign import mkFn10
1025− function mkFn10(fn) {
1026− return function(a, b, c, d, e, f, g, h, i, j) {
1027− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);
1030− """ :: 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
1032− -- | Apply a function of no arguments
1033− foreign import runFn0
1035− function runFn0(fn) {
1038− """ :: forall a. Fn0 a -> a
1040− -- | Apply a function of one argument
1041− foreign import runFn1
1043− function runFn1(fn) {
1044− return function(a) {
1048− """ :: forall a b. Fn1 a b -> a -> b
1050− -- | Apply a function of two arguments
1051− foreign import runFn2
1053− function runFn2(fn) {
1054− return function(a) {
1055− return function(b) {
1060− """ :: forall a b c. Fn2 a b c -> a -> b -> c
1062− -- | Apply a function of three arguments
1063− foreign import runFn3
1065− function runFn3(fn) {
1066− return function(a) {
1067− return function(b) {
1068− return function(c) {
1069− return fn(a, b, c);
1074− """ :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
1076− -- | Apply a function of four arguments
1077− foreign import runFn4
1079− function runFn4(fn) {
1080− return function(a) {
1081− return function(b) {
1082− return function(c) {
1083− return function(d) {
1084− return fn(a, b, c, d);
1090− """ :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
1092− -- | Apply a function of five arguments
1093− foreign import runFn5
1095− function runFn5(fn) {
1096− return function(a) {
1097− return function(b) {
1098− return function(c) {
1099− return function(d) {
1100− return function(e) {
1101− return fn(a, b, c, d, e);
1108− """ :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
1110− -- | Apply a function of six arguments
1111− foreign import runFn6
1113− function runFn6(fn) {
1114− return function(a) {
1115− return function(b) {
1116− return function(c) {
1117− return function(d) {
1118− return function(e) {
1119− return function(f) {
1120− return fn(a, b, c, d, e, f);
1128− """ :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
1130− -- | Apply a function of seven arguments
1131− foreign import runFn7
1133− function runFn7(fn) {
1134− return function(a) {
1135− return function(b) {
1136− return function(c) {
1137− return function(d) {
1138− return function(e) {
1139− return function(f) {
1140− return function(g) {
1141− return fn(a, b, c, d, e, f, g);
1150− """ :: 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
1152− -- | Apply a function of eight arguments
1153− foreign import runFn8
1155− function runFn8(fn) {
1156− return function(a) {
1157− return function(b) {
1158− return function(c) {
1159− return function(d) {
1160− return function(e) {
1161− return function(f) {
1162− return function(g) {
1163− return function(h) {
1164− return fn(a, b, c, d, e, f, g, h);
1174− """ :: 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
1176− -- | Apply a function of nine arguments
1177− foreign import runFn9
1179− function runFn9(fn) {
1180− return function(a) {
1181− return function(b) {
1182− return function(c) {
1183− return function(d) {
1184− return function(e) {
1185− return function(f) {
1186− return function(g) {
1187− return function(h) {
1188− return function(i) {
1189− return fn(a, b, c, d, e, f, g, h, i);
1200− """ :: 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
1202− -- | Apply a function of ten arguments
1203− foreign import runFn10
1205− function runFn10(fn) {
1206− return function(a) {
1207− return function(b) {
1208− return function(c) {
1209− return function(d) {
1210− return function(e) {
1211− return function(f) {
1212− return function(g) {
1213− return function(h) {
1214− return function(i) {
1215− return function(j) {
1216− return fn(a, b, c, d, e, f, g, h, i, j);
1228− """ :: 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
1230−module Prelude.Unsafe where
1232− -- | Find the element of an array at the specified index.
1234− -- | Note: this function can cause unpredictable failure at runtime if the index is out-of-bounds.
1235− foreign import unsafeIndex
1237− function unsafeIndex(xs) {
1238− return function(n) {
1242− """ :: forall a. [a] -> Number -> a
1244−module Control.Monad.Eff
1248− , untilE, whileE, forE, foreachE
1251− -- | The `Eff` type constructor is used to represent _native_ effects.
1253− -- | See [Handling Native Effects with the Eff Monad](https://github.com/purescript/purescript/wiki/Handling-Native-Effects-with-the-Eff-Monad) for more details.
1255− -- | 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.
1256− foreign import data Eff :: # ! -> * -> *
1258− foreign import returnE
1260− function returnE(a) {
1261− return function() {
1265− """ :: forall e a. a -> Eff e a
1267− foreign import bindE
1269− function bindE(a) {
1270− return function(f) {
1271− return function() {
1276− """ :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
1278− -- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled.
1280− -- | The `runPure` function can be used to run pure computations and obtain their result.
1281− type Pure a = forall e. Eff e a
1283− -- | Run a pure computation and return its result.
1285− -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1286− -- | is to use parentheses instead.
1287− foreign import runPure
1289− function runPure(f) {
1292− """ :: forall a. Pure a -> a
1294− instance functorEff :: Functor (Eff e) where
1297− instance applyEff :: Apply (Eff e) where
1300− instance applicativeEff :: Applicative (Eff e) where
1303− instance bindEff :: Bind (Eff e) where
1306− instance monadEff :: Monad (Eff e)
1308− -- | Loop until a condition becomes `true`.
1310− -- | `untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
1311− -- | until its return value is `true`.
1312− foreign import untilE
1314− function untilE(f) {
1315− return function() {
1320− """ :: forall e. Eff e Boolean -> Eff e Unit
1322− -- | Loop while a condition is `true`.
1324− -- | `whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
1325− -- | `true`, it runs the effectful computation `m` and loops. If not, the computation ends.
1326− foreign import whileE
1328− function whileE(f) {
1329− return function(a) {
1330− return function() {
1338− """ :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
1340− -- | Loop over a consecutive collection of numbers.
1342− -- | `forE lo hi f` runs the computation returned by the function `f` for each of the inputs
1343− -- | between `lo` (inclusive) and `hi` (exclusive).
1344− foreign import forE
1346− function forE(lo) {
1347− return function(hi) {
1348− return function(f) {
1349− return function() {
1350− for (var i = lo; i < hi; i++) {
1357− """ :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
1359− -- | Loop over an array of values.
1361− -- | `foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`.
1362− foreign import foreachE
1364− function foreachE(as) {
1365− return function(f) {
1366− return function() {
1367− for (var i = 0; i < as.length; i++) {
1373− """ :: forall e a. [a] -> (a -> Eff e Unit) -> Eff e Unit
1375−module Control.Monad.Eff.Unsafe where
1377− import Control.Monad.Eff
1379− -- | Change the type of an effectful computation, allowing it to be run in another context.
1381− -- | Note: use of this function can result in arbitrary side-effects.
1382− foreign import unsafeInterleaveEff
1384− function unsafeInterleaveEff(f) {
1387− """ :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
1389−module Debug.Trace where
1391− import Control.Monad.Eff
1393− -- | The `Trace` effect represents those computations which write to the console.
1394− foreign import data Trace :: !
1396− -- | Write a `String` to the console.
1397− foreign import trace
1399− function trace(s) {
1400− return function() {
1405− """ :: forall r. String -> Eff (trace :: Trace | r) Unit
1407− -- | Write a value to the console, using its `Show` instance to produce a `String`.
1408− print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
1409− print o = trace (show o)
1411−module Control.Monad.ST where
1413− import Control.Monad.Eff
1415− -- | The `ST` effect represents _local mutation_, i.e. mutation which does not "escape" into the surrounding computation.
1417− -- | An `ST` computation is parameterized by a phantom type which is used to restrict the set of reference cells it is allowed to access.
1419− -- | The `runST` function can be used to handle the `ST` effect.
1420− foreign import data ST :: * -> !
1422− -- | The type `STRef s a` represents a mutable reference holding a value of type `a`, which can be used with the `ST s` effect.
1423− foreign import data STRef :: * -> * -> *
1425− -- | Create a new mutable reference.
1426− foreign import newSTRef
1428− function newSTRef(val) {
1429− return function() {
1430− return { value: val };
1433− """ :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1435− -- | Read the current value of a mutable reference.
1436− foreign import readSTRef
1438− function readSTRef(ref) {
1439− return function() {
1443− """ :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1445− -- | Modify the value of a mutable reference by applying a function to the current value.
1446− foreign import modifySTRef
1448− function modifySTRef(ref) {
1449− return function(f) {
1450− return function() {
1451− return ref.value = f(ref.value);
1455− """ :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1457− -- | Set the value of a mutable reference.
1458− foreign import writeSTRef
1460− function writeSTRef(ref) {
1461− return function(a) {
1462− return function() {
1463− return ref.value = a;
1467− """ :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1469− -- | Run an `ST` computation.
1471− -- | 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
1472− -- | to the surrounding computation.
1474− -- | It may cause problems to apply this function using the `$` operator. The recommended approach is to use parentheses instead.
1475− foreign import runST
1477− function runST(f) {
1480− """ :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1482− -- | A convenience function which combines `runST` with `runPure`, which can be used when the only required effect is `ST`.
1484− -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1485− -- | is to use parentheses instead.
1486− pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
1487− pureST st = runPure (runST st)