@@ -1,1525 +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− foreign import refEq
598− function refEq(r1) {
599− return function(r2) {
603− """ :: forall a. a -> a -> Boolean
605− foreign import refIneq
607− function refIneq(r1) {
608− return function(r2) {
612− """ :: forall a. a -> a -> Boolean
614− foreign import eqArrayImpl
616− function eqArrayImpl(f) {
617− return function(xs) {
618− return function(ys) {
619− if (xs.length !== ys.length) return false;
620− for (var i = 0; i < xs.length; i++) {
621− if (!f(xs[i])(ys[i])) return false;
627− """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
629− -- | The `Ordering` data type represents the three possible outcomes of
630− -- | comparing two values:
632− -- | `LT` - The first value is _less than_ the second.
633− -- | `GT` - The first value is _greater than_ the second.
634− -- | `EQ` - The first value is _equal to_ or _incomparable to_ the second.
635− data Ordering = LT | GT | EQ
637− -- | The `Ord` type class represents types which support comparisons.
639− -- | `Ord` instances should satisfy the laws of _partially orderings_:
641− -- | - Reflexivity: `a <= a`
642− -- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
643− -- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
644− class (Eq a) <= Ord a where
645− compare :: a -> a -> Ordering
647− instance ordBoolean :: Ord Boolean where
648− compare false false = EQ
649− compare false true = LT
650− compare true true = EQ
651− compare true false = GT
653− instance ordNumber :: Ord Number where
654− compare = unsafeCompare
656− instance ordString :: Ord String where
657− compare = unsafeCompare
659− instance ordUnit :: Ord Unit where
662− instance ordArray :: (Ord a) => Ord [a] where
666− compare (x:xs) (y:ys) = case compare x y of
670− instance eqOrdering :: Eq Ordering where
675− (/=) x y = not (x == y)
682− -- | Test whether one value is _strictly less than_ another.
683− (<) :: forall a. (Ord a) => a -> a -> Boolean
684− (<) a1 a2 = case a1 `compare` a2 of
688− -- | Test whether one value is _strictly greater than_ another.
689− (>) :: forall a. (Ord a) => a -> a -> Boolean
690− (>) a1 a2 = case a1 `compare` a2 of
694− -- | Test whether one value is _non-strictly less than_ another.
695− (<=) :: forall a. (Ord a) => a -> a -> Boolean
696− (<=) a1 a2 = case a1 `compare` a2 of
700− -- | Test whether one value is _non-strictly greater than_ another.
701− (>=) :: forall a. (Ord a) => a -> a -> Boolean
702− (>=) a1 a2 = case a1 `compare` a2 of
706− unsafeCompare :: forall a. a -> a -> Ordering
707− unsafeCompare = unsafeCompareImpl LT EQ GT
709− foreign import unsafeCompareImpl
711− function unsafeCompareImpl(lt) {
712− return function(eq) {
713− return function(gt) {
714− return function(x) {
715− return function(y) {
716− return x < y ? lt : x > y ? gt : eq;
722− """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
724− -- | The `Bounded` type class represents types that are finite partially
727− -- | Instances should satisfy the following law in addition to the `Ord` laws:
729− -- | - Ordering: `bottom <= a <= top`
730− class (Ord a) <= Bounded a where
734− instance boundedBoolean :: Bounded Boolean where
738− instance boundedUnit :: Bounded Unit where
742− -- | The `Lattice` type class represents types that are partially ordered
743− -- | sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`).
745− -- | Instances should satisfy the following laws in addition to the `Ord`
748− -- | - Associativity:
749− -- | - `a || (b || c) = (a || b) || c`
750− -- | - `a && (b && c) = (a && b) && c`
751− -- | - Commutativity:
752− -- | - `a || b = b || a`
753− -- | - `a && b = b && a`
755− -- | - `a || (a && b) = a`
756− -- | - `a && (a || b) = a`
760− class (Ord a) <= Lattice a where
764− instance latticeBoolean :: Lattice Boolean where
771− -- | The `sup` operator.
772− (||) :: forall a. (Lattice a) => a -> a -> a
775− -- | The `inf` operator.
776− (&&) :: forall a. (Lattice a) => a -> a -> a
779− -- | The `BoundedLattice` type class represents types that are finite
782− -- | Instances should satisfy the following law in addition to the `Lattice`
783− -- | and `Bounded` laws:
786− -- | - `a || bottom = a`
787− -- | - `a && top = a`
788− -- | - Annihiliation:
789− -- | - `a || top = top`
790− -- | - `a && bottom = bottom`
791− class (Bounded a, Lattice a) <= BoundedLattice a
793− instance boundedLatticeBoolean :: BoundedLattice Boolean
795− -- | The `ComplementedLattice` type class represents types that are lattices
796− -- | where every member is also uniquely complemented.
798− -- | Instances should satisfy the following law in addition to the
799− -- | `BoundedLattice` laws:
801− -- | - Complemented:
802− -- | - `not a || a == top`
803− -- | - `not a && a == bottom`
804− -- | - Double negation:
805− -- | - `not <<< not == id`
806− class (BoundedLattice a) <= ComplementedLattice a where
809− instance complementedLatticeBoolean :: ComplementedLattice Boolean where
812− -- | The `DistributiveLattice` type class represents types that are lattices
813− -- | where the `&&` and `||` distribute over each other.
815− -- | Instances should satisfy the following law in addition to the `Lattice`
818− -- | - Distributivity: `x && (y || z) = (x && y) || (x && z)`
819− class (Lattice a) <= DistributiveLattice a
821− instance distributiveLatticeBoolean :: DistributiveLattice Boolean
823− -- | The `BooleanAlgebra` type class represents types that are Boolean
824− -- | algebras, also known as Boolean lattices.
826− -- | Instances should satisfy the `ComplementedLattice` and
827− -- | `DistributiveLattice` laws.
828− class (ComplementedLattice a, DistributiveLattice a) <= BooleanAlgebra a
830− instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
832− foreign import boolOr
834− function boolOr(b1) {
835− return function(b2) {
839− """ :: Boolean -> Boolean -> Boolean
841− foreign import boolAnd
843− function boolAnd(b1) {
844− return function(b2) {
848− """ :: Boolean -> Boolean -> Boolean
850− foreign import boolNot
852− function boolNot(b) {
855− """ :: Boolean -> Boolean
857− -- | The `Show` type class represents those types which can be converted into
858− -- | a human-readable `String` representation.
860− -- | While not required, it is recommended that for any expression `x`, the
861− -- | string `show x` be executable PureScript code which evaluates to the same
862− -- | value as the expression `x`.
866− instance showBoolean :: Show Boolean where
868− show false = "false"
870− instance showNumber :: Show Number where
871− show = showNumberImpl
873− instance showString :: Show String where
874− show = showStringImpl
876− instance showUnit :: Show Unit where
879− instance showArray :: (Show a) => Show [a] where
880− show = showArrayImpl show
882− instance showOrdering :: Show Ordering where
887− foreign import showNumberImpl
889− function showNumberImpl(n) {
890− return n.toString();
892− """ :: Number -> String
894− foreign import showStringImpl
896− function showStringImpl(s) {
897− return JSON.stringify(s);
899− """ :: String -> String
901− foreign import showArrayImpl
903− function showArrayImpl(f) {
904− return function(xs) {
906− for (var i = 0, l = xs.length; i < l; i++) {
909− return '[' + ss.join(',') + ']';
912− """ :: forall a. (a -> String) -> [a] -> String
914−module Data.Function where
916− -- | The `on` function is used to change the domain of a binary operator.
918− -- | For example, we can create a function which compares two records based on the values of their `x` properties:
921− -- | compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
922− -- | compareX = compare `on` _.x
924− on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
925− on f g x y = g x `f` g y
927− -- | A function of zero arguments
928− foreign import data Fn0 :: * -> *
930− -- | A function of one argument
931− foreign import data Fn1 :: * -> * -> *
933− -- | A function of two arguments
934− foreign import data Fn2 :: * -> * -> * -> *
936− -- | A function of three arguments
937− foreign import data Fn3 :: * -> * -> * -> * -> *
939− -- | A function of four arguments
940− foreign import data Fn4 :: * -> * -> * -> * -> * -> *
942− -- | A function of five arguments
943− foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
945− -- | A function of six arguments
946− foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
948− -- | A function of seven arguments
949− foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
951− -- | A function of eight arguments
952− foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
954− -- | A function of nine arguments
955− foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
957− -- | A function of ten arguments
958− foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
960− -- | Create a function of no arguments
961− foreign import mkFn0
963− function mkFn0(fn) {
968− """ :: forall a. (Unit -> a) -> Fn0 a
970− -- | Create a function of one argument
971− foreign import mkFn1
973− function mkFn1(fn) {
974− return function(a) {
978− """ :: forall a b. (a -> b) -> Fn1 a b
980− -- | Create a function of two arguments from a curried function
981− foreign import mkFn2
983− function mkFn2(fn) {
984− return function(a, b) {
988− """ :: forall a b c. (a -> b -> c) -> Fn2 a b c
990− -- | Create a function of three arguments from a curried function
991− foreign import mkFn3
993− function mkFn3(fn) {
994− return function(a, b, c) {
998− """ :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
1000− -- | Create a function of four arguments from a curried function
1001− foreign import mkFn4
1003− function mkFn4(fn) {
1004− return function(a, b, c, d) {
1005− return fn(a)(b)(c)(d);
1008− """ :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
1010− -- | Create a function of five arguments from a curried function
1011− foreign import mkFn5
1013− function mkFn5(fn) {
1014− return function(a, b, c, d, e) {
1015− return fn(a)(b)(c)(d)(e);
1018− """ :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
1020− -- | Create a function of six arguments from a curried function
1021− foreign import mkFn6
1023− function mkFn6(fn) {
1024− return function(a, b, c, d, e, f) {
1025− return fn(a)(b)(c)(d)(e)(f);
1028− """ :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
1030− -- | Create a function of seven arguments from a curried function
1031− foreign import mkFn7
1033− function mkFn7(fn) {
1034− return function(a, b, c, d, e, f, g) {
1035− return fn(a)(b)(c)(d)(e)(f)(g);
1038− """ :: 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
1040− -- | Create a function of eight arguments from a curried function
1041− foreign import mkFn8
1043− function mkFn8(fn) {
1044− return function(a, b, c, d, e, f, g, h) {
1045− return fn(a)(b)(c)(d)(e)(f)(g)(h);
1048− """ :: 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
1050− -- | Create a function of nine arguments from a curried function
1051− foreign import mkFn9
1053− function mkFn9(fn) {
1054− return function(a, b, c, d, e, f, g, h, i) {
1055− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i);
1058− """ :: 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
1060− -- | Create a function of ten arguments from a curried function
1061− foreign import mkFn10
1063− function mkFn10(fn) {
1064− return function(a, b, c, d, e, f, g, h, i, j) {
1065− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);
1068− """ :: 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
1070− -- | Apply a function of no arguments
1071− foreign import runFn0
1073− function runFn0(fn) {
1076− """ :: forall a. Fn0 a -> a
1078− -- | Apply a function of one argument
1079− foreign import runFn1
1081− function runFn1(fn) {
1082− return function(a) {
1086− """ :: forall a b. Fn1 a b -> a -> b
1088− -- | Apply a function of two arguments
1089− foreign import runFn2
1091− function runFn2(fn) {
1092− return function(a) {
1093− return function(b) {
1098− """ :: forall a b c. Fn2 a b c -> a -> b -> c
1100− -- | Apply a function of three arguments
1101− foreign import runFn3
1103− function runFn3(fn) {
1104− return function(a) {
1105− return function(b) {
1106− return function(c) {
1107− return fn(a, b, c);
1112− """ :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
1114− -- | Apply a function of four arguments
1115− foreign import runFn4
1117− function runFn4(fn) {
1118− return function(a) {
1119− return function(b) {
1120− return function(c) {
1121− return function(d) {
1122− return fn(a, b, c, d);
1128− """ :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
1130− -- | Apply a function of five arguments
1131− foreign import runFn5
1133− function runFn5(fn) {
1134− return function(a) {
1135− return function(b) {
1136− return function(c) {
1137− return function(d) {
1138− return function(e) {
1139− return fn(a, b, c, d, e);
1146− """ :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
1148− -- | Apply a function of six arguments
1149− foreign import runFn6
1151− function runFn6(fn) {
1152− return function(a) {
1153− return function(b) {
1154− return function(c) {
1155− return function(d) {
1156− return function(e) {
1157− return function(f) {
1158− return fn(a, b, c, d, e, f);
1166− """ :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
1168− -- | Apply a function of seven arguments
1169− foreign import runFn7
1171− function runFn7(fn) {
1172− return function(a) {
1173− return function(b) {
1174− return function(c) {
1175− return function(d) {
1176− return function(e) {
1177− return function(f) {
1178− return function(g) {
1179− return fn(a, b, c, d, e, f, g);
1188− """ :: 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
1190− -- | Apply a function of eight arguments
1191− foreign import runFn8
1193− function runFn8(fn) {
1194− return function(a) {
1195− return function(b) {
1196− return function(c) {
1197− return function(d) {
1198− return function(e) {
1199− return function(f) {
1200− return function(g) {
1201− return function(h) {
1202− return fn(a, b, c, d, e, f, g, h);
1212− """ :: 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
1214− -- | Apply a function of nine arguments
1215− foreign import runFn9
1217− function runFn9(fn) {
1218− return function(a) {
1219− return function(b) {
1220− return function(c) {
1221− return function(d) {
1222− return function(e) {
1223− return function(f) {
1224− return function(g) {
1225− return function(h) {
1226− return function(i) {
1227− return fn(a, b, c, d, e, f, g, h, i);
1238− """ :: 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
1240− -- | Apply a function of ten arguments
1241− foreign import runFn10
1243− function runFn10(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 function(j) {
1254− return fn(a, b, c, d, e, f, g, h, i, j);
1266− """ :: 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
1268−module Prelude.Unsafe where
1270− -- | Find the element of an array at the specified index.
1272− -- | Note: this function can cause unpredictable failure at runtime if the index is out-of-bounds.
1273− foreign import unsafeIndex
1275− function unsafeIndex(xs) {
1276− return function(n) {
1280− """ :: forall a. [a] -> Number -> a
1282−module Control.Monad.Eff
1286− , untilE, whileE, forE, foreachE
1289− -- | The `Eff` type constructor is used to represent _native_ effects.
1291− -- | See [Handling Native Effects with the Eff Monad](https://github.com/purescript/purescript/wiki/Handling-Native-Effects-with-the-Eff-Monad) for more details.
1293− -- | 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.
1294− foreign import data Eff :: # ! -> * -> *
1296− foreign import returnE
1298− function returnE(a) {
1299− return function() {
1303− """ :: forall e a. a -> Eff e a
1305− foreign import bindE
1307− function bindE(a) {
1308− return function(f) {
1309− return function() {
1314− """ :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
1316− -- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled.
1318− -- | The `runPure` function can be used to run pure computations and obtain their result.
1319− type Pure a = forall e. Eff e a
1321− -- | Run a pure computation and return its result.
1323− -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1324− -- | is to use parentheses instead.
1325− foreign import runPure
1327− function runPure(f) {
1330− """ :: forall a. Pure a -> a
1332− instance functorEff :: Functor (Eff e) where
1335− instance applyEff :: Apply (Eff e) where
1338− instance applicativeEff :: Applicative (Eff e) where
1341− instance bindEff :: Bind (Eff e) where
1344− instance monadEff :: Monad (Eff e)
1346− -- | Loop until a condition becomes `true`.
1348− -- | `untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
1349− -- | until its return value is `true`.
1350− foreign import untilE
1352− function untilE(f) {
1353− return function() {
1358− """ :: forall e. Eff e Boolean -> Eff e Unit
1360− -- | Loop while a condition is `true`.
1362− -- | `whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
1363− -- | `true`, it runs the effectful computation `m` and loops. If not, the computation ends.
1364− foreign import whileE
1366− function whileE(f) {
1367− return function(a) {
1368− return function() {
1376− """ :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
1378− -- | Loop over a consecutive collection of numbers.
1380− -- | `forE lo hi f` runs the computation returned by the function `f` for each of the inputs
1381− -- | between `lo` (inclusive) and `hi` (exclusive).
1382− foreign import forE
1384− function forE(lo) {
1385− return function(hi) {
1386− return function(f) {
1387− return function() {
1388− for (var i = lo; i < hi; i++) {
1395− """ :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
1397− -- | Loop over an array of values.
1399− -- | `foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`.
1400− foreign import foreachE
1402− function foreachE(as) {
1403− return function(f) {
1404− return function() {
1405− for (var i = 0; i < as.length; i++) {
1411− """ :: forall e a. [a] -> (a -> Eff e Unit) -> Eff e Unit
1413−module Control.Monad.Eff.Unsafe where
1415− import Control.Monad.Eff
1417− -- | Change the type of an effectful computation, allowing it to be run in another context.
1419− -- | Note: use of this function can result in arbitrary side-effects.
1420− foreign import unsafeInterleaveEff
1422− function unsafeInterleaveEff(f) {
1425− """ :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
1427−module Debug.Trace where
1429− import Control.Monad.Eff
1431− -- | The `Trace` effect represents those computations which write to the console.
1432− foreign import data Trace :: !
1434− -- | Write a `String` to the console.
1435− foreign import trace
1437− function trace(s) {
1438− return function() {
1443− """ :: forall r. String -> Eff (trace :: Trace | r) Unit
1445− -- | Write a value to the console, using its `Show` instance to produce a `String`.
1446− print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
1447− print o = trace (show o)
1449−module Control.Monad.ST where
1451− import Control.Monad.Eff
1453− -- | The `ST` effect represents _local mutation_, i.e. mutation which does not "escape" into the surrounding computation.
1455− -- | An `ST` computation is parameterized by a phantom type which is used to restrict the set of reference cells it is allowed to access.
1457− -- | The `runST` function can be used to handle the `ST` effect.
1458− foreign import data ST :: * -> !
1460− -- | The type `STRef s a` represents a mutable reference holding a value of type `a`, which can be used with the `ST s` effect.
1461− foreign import data STRef :: * -> * -> *
1463− -- | Create a new mutable reference.
1464− foreign import newSTRef
1466− function newSTRef(val) {
1467− return function() {
1468− return { value: val };
1471− """ :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1473− -- | Read the current value of a mutable reference.
1474− foreign import readSTRef
1476− function readSTRef(ref) {
1477− return function() {
1481− """ :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1483− -- | Modify the value of a mutable reference by applying a function to the current value.
1484− foreign import modifySTRef
1486− function modifySTRef(ref) {
1487− return function(f) {
1488− return function() {
1489− return ref.value = f(ref.value);
1493− """ :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1495− -- | Set the value of a mutable reference.
1496− foreign import writeSTRef
1498− function writeSTRef(ref) {
1499− return function(a) {
1500− return function() {
1501− return ref.value = a;
1505− """ :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1507− -- | Run an `ST` computation.
1509− -- | 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
1510− -- | to the surrounding computation.
1512− -- | It may cause problems to apply this function using the `$` operator. The recommended approach is to use parentheses instead.
1513− foreign import runST
1515− function runST(f) {
1518− """ :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1520− -- | A convenience function which combines `runST` with `runPure`, which can be used when the only required effect is `ST`.
1522− -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1523− -- | is to use parentheses instead.
1524− pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
1525− pureST st = runPure (runST st)