@@ -1,1570 +0,0 @@
6− , Semigroupoid, (<<<), (>>>)
11− , Functor, (<$>), (<#>), void
13− , Applicative, pure, liftA1
15− , Monad, return, liftM1, ap
16− , Semiring, (+), zero, (*), one
17− , ModuloSemiring, (/), mod
24− , Ord, Ordering(..), compare, (<), (>), (<=), (>=)
25− , Bounded, top, bottom
26− , Lattice, sup, inf, (||), (&&)
28− , ComplementedLattice, not
29− , DistributiveLattice
31− , Bits, (.&.), (.|.), (.^.), shl, shr, zshr, complement
32− , Semigroup, (<>), (++)
36− -- | An alias for `true`, which can be useful in guard clauses:
39− -- | max x y | x >= y = x
46− -- | Flips the order of the arguments to a function of two arguments.
49− -- | flip const 1 2 = const 2 1 = 2
52− flip :: forall a b c. (a -> b -> c) -> b -> a -> c
55− -- | Returns its first argument and ignores its second.
58− -- | const 1 "hello" = 1
61− const :: forall a b. a -> b -> a
64− -- | This function returns its first argument, and can be used to assert type equalities.
65− -- | This can be useful when types are otherwise ambiguous.
68− -- | main = print $ [] `asTypeOf` [0]
71− -- | If instead, we had written `main = print []`, the type of the argument `[]` would have
72− -- | been ambiguous, resulting in a compile-time error.
73− asTypeOf :: forall a. a -> a -> a
79− -- | A `Semigroupoid` is similar to a [`Category`](#category) but does not require an identity
80− -- | element `id`, just composable morphisms.
82− -- | `Semigroupoid`s should obey the following rule:
84− -- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
86− -- | One example of a `Semigroupoid` is the function type constructor `(->)`, with `(<<<)` defined
87− -- | as function composition.
88− class Semigroupoid a where
89− (<<<) :: forall b c d. a c d -> a b c -> a b d
91− instance semigroupoidArr :: Semigroupoid (->) where
92− (<<<) f g x = f (g x)
94− -- | Forwards composition, or `(<<<)` with its arguments reversed.
95− (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
98− -- | `Category`s consist of objects and composable morphisms between them, and as such are
99− -- | [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids` must have an identity element.
101− -- | `Category`s should obey the following rules.
103− -- | - Left Identity: `id <<< p = p`
104− -- | - Right Identity: `p <<< id = p`
106− class (Semigroupoid a) <= Category a where
107− id :: forall t. a t t
109− instance categoryArr :: Category (->) where
115− -- | Applies a function to its argument.
118− -- | length $ groupBy productCategory $ filter isInStock $ products
121− -- | is equivalent to
124− -- | length (groupBy productCategory (filter isInStock products))
127− -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
128− -- | `a $ b $ c $ d x` = `a $ (b $ (c $ (d $ x)))` = `a (b (c (d x)))`
130− ($) :: forall a b. (a -> b) -> a -> b
133− -- | Applies an argument to a function.
136− -- | products # filter isInStock # groupBy productCategory # length
139− -- | is equivalent to
142− -- | length (groupBy productCategory (filter isInStock products))
145− -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
146− -- | `x # a # b # c # d` = `(((x # a) # b) # c) # d` = `d (c (b (a x)))`
148− (#) :: forall a b. a -> (a -> b) -> b
153− -- | An infix alias for `cons`.
155− -- | Note, the running time of this function is `O(n)`.
156− (:) :: forall a. a -> [a] -> [a]
159− -- | Attaches an element to the front of an array, creating a new array.
162− -- | cons 1 [2, 3, 4] = [1, 2, 3, 4]
165− -- | Note, the running time of this function is `O(n)`.
169− return function(l) {
170− return [e].concat(l);
173− """ :: forall a. a -> [a] -> [a]
175− -- | The `Show` type class represents those types which can be converted into a human-readable `String` representation.
177− -- | While not required, it is recommended that for any expression `x`, the string `show x` be executable PureScript code
178− -- | which evaluates to the same value as the expression `x`.
182− foreign import showStringImpl
184− function showStringImpl(s) {
185− return JSON.stringify(s);
187− """ :: String -> String
189− instance showUnit :: Show Unit where
190− show (Unit {}) = "Unit {}"
192− instance showString :: Show String where
193− show = showStringImpl
195− instance showBoolean :: Show Boolean where
197− show false = "false"
199− foreign import showNumberImpl
201− function showNumberImpl(n) {
202− return n.toString();
204− """ :: Number -> String
206− instance showNumber :: Show Number where
207− show = showNumberImpl
209− foreign import showArrayImpl
211− function showArrayImpl(f) {
212− return function(xs) {
214− for (var i = 0, l = xs.length; i < l; i++) {
217− return '[' + ss.join(',') + ']';
220− """ :: forall a. (a -> String) -> [a] -> String
222− instance showArray :: (Show a) => Show [a] where
223− show = showArrayImpl show
228− -- | A `Functor` is a type constructor which supports a mapping operation `(<$>)`.
230− -- | `(<$>)` can be used to turn functions `a -> b` into functions `f a -> f b` whose argument and return
231− -- | types use the type constructor `f` to represent some computational context.
233− -- | `Functor` instances should satisfy the following laws:
235− -- | - Identity: `(<$>) id = id`
236− -- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
238− class Functor f where
239− (<$>) :: forall a b. (a -> b) -> f a -> f b
241− -- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
244− -- | [1, 2, 3] <#> \n -> n * n
246− (<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
247− (<#>) fa f = f <$> fa
249− -- | The `void` function is used to ignore the type wrapped by a [`Functor`](#functor), replacing it with `Unit` and
250− -- | keeping only the type information provided by the type constructor itself.
252− -- | `void` is often useful when using `do` notation to change the return type of a monadic computation:
255− -- | main = forE 1 10 \n -> void do
259− void :: forall f a. (Functor f) => f a -> f Unit
260− void fa = const unit <$> fa
264− -- | The `Apply` class provides the `(<*>)` which is used to apply a function to an argument under a type constructor.
266− -- | `Apply` can be used to lift functions of two or more arguments to work on values wrapped with the type constructor `f`.
267− -- | It might also be understood in terms of the `lift2` function:
270− -- | lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
271− -- | lift2 f a b = f <$> a <*> b
274− -- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts the function application operator `($)` to arguments
275− -- | wrapped with the type constructor `f`.
277− -- | `Apply` instances should satisfy the following law:
279− -- | - Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
281− -- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
282− class (Functor f) <= Apply f where
283− (<*>) :: forall a b. f (a -> b) -> f a -> f b
285− -- | The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
286− -- | create values of type `f a` from values of type `a`.
288− -- | Where [`Apply`](#apply) provides the ability to lift functions of two or more arguments to functions whose arguments are wrapped using `f`,
289− -- | and [`Functor`](#functor) provides the ability to lift functions of one argument, `pure` can be seen as the function which lifts functions of
290− -- | _zero_ arguments. That is, `Applicative` functors support a lifting operation for any number of function arguments.
292− -- | `Applicative` instances should satisfy the following laws:
294− -- | - Identity: `(pure id) <*> v = v`
295− -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
296− -- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
297− -- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
299− class (Apply f) <= Applicative f where
300− pure :: forall a. a -> f a
302− -- | `liftA1` provides a default implementation of `(<$>)` for any [`Applicative`](#applicative) functor,
303− -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass relationship.
305− -- | `liftA1` can therefore be used to write [`Functor`](#functor) instances as follows:
308− -- | instance functorF :: Functor F where
311− liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
312− liftA1 f a = pure f <*> a
316− -- | The `Bind` type class extends the [`Apply`](#apply) type class with a "bind" operation `(>>=)` which composes computations
317− -- | in sequence, using the return value of one computation to determine the next computation.
319− -- | The `>>=` operator can also be expressed using `do` notation, as follows:
322− -- | x >>= f = do y <- x
326− -- | where the function argument of `f` is given the name `y`.
328− -- | `Bind` instances should satisfy the following law:
330− -- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
332− -- | Or, expressed using `do` notation:
334− -- | - Associativity: `do { z <- do { y <- x ; f y } ; g z } = do { k <- x ; do { y <- f k ; g y } }`
336− -- | Associativity tells us that we can regroup operations which use do-notation, so that we can unambiguously write, for example:
343− class (Apply m) <= Bind m where
344− (>>=) :: forall a b. m a -> (a -> m b) -> m b
346− -- | The `Monad` type class combines the operations of the `Bind` and `Applicative` type classes. Therefore, `Monad` instances
347− -- | represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
349− -- | `Monad` instances should satisfy the following laws:
351− -- | - Left Identity: `pure x >>= f = f x`
352− -- | - Right Identity: `x >>= pure = x`
354− -- | Or, expressed using `do` notation:
356− -- | - Left Identity: `do { y <- pure x ; f y } = f x`
357− -- | - Right Identity: `do { y <- x ; pure y } = x`
359− class (Applicative m, Bind m) <= Monad m
361− -- | `return` is an alias for `pure`.
362− return :: forall m a. (Monad m) => a -> m a
365− -- | `liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
366− -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
368− -- | `liftM1` can therefore be used to write [`Functor`](#functor) instances as follows:
371− -- | instance functorF :: Functor F where
374− liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
379− -- | `ap` provides a default implementation of `(<*>)` for any [`Monad`](#monad),
380− -- | without using `(<*>)` as provided by the [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
382− -- | `ap` can therefore be used to write [`Apply`](#apply) instances as follows:
385− -- | instance applyF :: Apply F where
388− ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
394− instance functorArr :: Functor ((->) r) where
397− instance applyArr :: Apply ((->) r) where
398− (<*>) f g x = f x (g x)
400− instance applicativeArr :: Applicative ((->) r) where
403− instance bindArr :: Bind ((->) r) where
404− (>>=) m f x = f (m x) x
406− instance monadArr :: Monad ((->) r)
415− -- | Addition and multiplication, satisfying the following laws:
417− -- | - `a` is a commutative monoid under addition
418− -- | - `a` is a monoid under multiplication
419− -- | - multiplication distributes over addition
420− -- | - multiplication by `zero` annihilates `a`
422− class Semiring a where
428− -- | Addition, multiplication, modulo operation and division, satisfying:
430− -- | - ```a / b * b + (a `mod` b) = a```
432− class (Semiring a) <= ModuloSemiring a where
436− -- | Addition, multiplication, and subtraction.
438− -- | Has the same laws as `Semiring` but additionally satisfying:
440− -- | - `a` is an abelian group under addition
442− class (Semiring a) <= Ring a where
445− negate :: forall a. (Ring a) => a -> a
448− -- | Ring where every nonzero element has a multiplicative inverse so that:
450− -- | - ```a `mod` b = zero```
452− class (Ring a, ModuloSemiring a) <= DivisionRing a
454− -- | A commutative field
455− class (DivisionRing a) <= Num a
457− foreign import numAdd
459− function numAdd(n1) {
460− return function(n2) {
464− """ :: Number -> Number -> Number
466− foreign import numSub
468− function numSub(n1) {
469− return function(n2) {
473− """ :: Number -> Number -> Number
475− foreign import numMul
477− function numMul(n1) {
478− return function(n2) {
482− """ :: Number -> Number -> Number
484− foreign import numDiv
486− function numDiv(n1) {
487− return function(n2) {
491− """ :: Number -> Number -> Number
493− foreign import numMod
495− function numMod(n1) {
496− return function(n2) {
500− """ :: Number -> Number -> Number
504− instance semiringNumber :: Semiring Number where
510− instance ringNumber :: Ring Number where
513− instance moduloSemiringNumber :: ModuloSemiring Number where
517− instance divisionRingNumber :: DivisionRing Number
519− instance numNumber :: Num Number
521− -- | The `Unit` type has a single inhabitant, called `unit`. It represents values with no computational content.
523− -- | `Unit` is often used, wrapped in a monadic type constructor, as the return type of a computation where only
524− -- | the _effects_ are important.
525− newtype Unit = Unit {}
527− -- | `unit` is the sole inhabitant of the `Unit` type.
534− -- | The `Eq` type class represents types which support decidable equality.
536− -- | `Eq` instances should satisfy the following laws:
538− -- | - Reflexivity: `x == x = true`
539− -- | - Symmetry: `x == y = y == x`
540− -- | - Transitivity: if `x == y` and `y == z` then `x == z`
541− -- | - Negation: `x /= y = not (x == y)`
543− -- | `(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
545− (==) :: a -> a -> Boolean
546− (/=) :: a -> a -> Boolean
548− foreign import refEq
550− function refEq(r1) {
551− return function(r2) {
555− """ :: forall a. a -> a -> Boolean
557− foreign import refIneq
559− function refIneq(r1) {
560− return function(r2) {
564− """ :: forall a. a -> a -> Boolean
566− instance eqUnit :: Eq Unit where
567− (==) (Unit {}) (Unit {}) = true
568− (/=) (Unit {}) (Unit {}) = false
570− instance eqString :: Eq String where
574− instance eqNumber :: Eq Number where
578− instance eqBoolean :: Eq Boolean where
582− foreign import eqArrayImpl
584− function eqArrayImpl(f) {
585− return function(xs) {
586− return function(ys) {
587− if (xs.length !== ys.length) return false;
588− for (var i = 0; i < xs.length; i++) {
589− if (!f(xs[i])(ys[i])) return false;
595− """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
597− instance eqArray :: (Eq a) => Eq [a] where
598− (==) xs ys = eqArrayImpl (==) xs ys
599− (/=) xs ys = not (xs == ys)
601− -- | The `Ordering` data type represents the three possible outcomes of comparing two values:
603− -- | `LT` - The first value is _less than_ the second.
604− -- | `GT` - The first value is _greater than_ the second.
605− -- | `EQ` - The first value is _equal to_ or _incomparable to_ the second.
606− data Ordering = LT | GT | EQ
608− instance eqOrdering :: Eq Ordering where
613− (/=) x y = not (x == y)
615− instance showOrdering :: Show Ordering where
620− instance semigroupOrdering :: Semigroup Ordering where
625− -- | The `Ord` type class represents types which support comparisons.
627− -- | `Ord` instances should satisfy the laws of _partially orderings_:
629− -- | - Reflexivity: `a <= a`
630− -- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
631− -- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
633− class (Eq a) <= Ord a where
634− compare :: a -> a -> Ordering
638− -- | Test whether one value is _strictly less than_ another.
639− (<) :: forall a. (Ord a) => a -> a -> Boolean
640− (<) a1 a2 = case a1 `compare` a2 of
646− -- | Test whether one value is _strictly greater than_ another.
647− (>) :: forall a. (Ord a) => a -> a -> Boolean
648− (>) a1 a2 = case a1 `compare` a2 of
654− -- | Test whether one value is _non-strictly less than_ another.
655− (<=) :: forall a. (Ord a) => a -> a -> Boolean
656− (<=) a1 a2 = case a1 `compare` a2 of
662− -- | Test whether one value is _non-strictly greater than_ another.
663− (>=) :: forall a. (Ord a) => a -> a -> Boolean
664− (>=) a1 a2 = case a1 `compare` a2 of
668− foreign import unsafeCompareImpl
670− function unsafeCompareImpl(lt) {
671− return function(eq) {
672− return function(gt) {
673− return function(x) {
674− return function(y) {
675− return x < y ? lt : x > y ? gt : eq;
681− """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
683− unsafeCompare :: forall a. a -> a -> Ordering
684− unsafeCompare = unsafeCompareImpl LT EQ GT
686− instance ordUnit :: Ord Unit where
687− compare (Unit {}) (Unit {}) = EQ
689− instance ordBoolean :: Ord Boolean where
690− compare false false = EQ
691− compare false true = LT
692− compare true true = EQ
693− compare true false = GT
695− instance ordNumber :: Ord Number where
696− compare = unsafeCompare
698− instance ordString :: Ord String where
699− compare = unsafeCompare
701− instance ordArray :: (Ord a) => Ord [a] where
705− compare (x:xs) (y:ys) = case compare x y of
709− -- | The `Bounded` type class represents types that are finite partially
712− -- | Instances should satisfy the following law in addition to the `Ord` laws:
714− -- | - Ordering: `bottom <= a <= top`
715− class (Ord a) <= Bounded a where
719− instance boundedBoolean :: Bounded Boolean where
723− -- | The `Lattice` type class represents types that are partially ordered
724− -- | sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`).
726− -- | Instances should satisfy the following laws in addition to the `Ord`
729− -- | - Associativity:
730− -- | - `a || (b || c) = (a || b) || c`
731− -- | - `a && (b && c) = (a && b) && c`
732− -- | - Commutativity:
733− -- | - `a || b = b || a`
734− -- | - `a && b = b && a`
736− -- | - `a || (a && b) = a`
737− -- | - `a && (a || b) = a`
741− class (Ord a) <= Lattice a where
745− instance latticeBoolean :: Lattice Boolean where
749− -- | The `BoundedLattice` type class represents types that are finite
752− -- | Instances should satisfy the following law in addition to the `Lattice`
753− -- | and `Bounded` laws:
756− -- | - `a || bottom = a`
757− -- | - `a && top = a`
758− -- | - Annihiliation:
759− -- | - `a || top = top`
760− -- | - `a && bottom = bottom`
761− class (Bounded a, Lattice a) <= BoundedLattice a
763− instance boundedLatticeBoolean :: BoundedLattice Boolean
765− -- | The `ComplementedLattice` type class represents types that are lattices
766− -- | where every member is also uniquely complemented.
768− -- | Instances should satisfy the following law in addition to the
769− -- | `BoundedLattice` laws:
771− -- | - Complemented:
772− -- | - `not a || a == top`
773− -- | - `not a && a == bottom`
774− -- | - Double negation:
775− -- | - `not <<< not == id`
776− class (BoundedLattice a) <= ComplementedLattice a where
779− instance complementedLatticeBoolean :: ComplementedLattice Boolean where
782− -- | The `DistributiveLattice` type class represents types that are lattices
783− -- | where the `&&` and `||` distribute over each other.
785− -- | Instances should satisfy the following law in addition to the `Lattice`
788− -- | - Distributivity: `x && (y || z) = (x && y) || (x && z)`
789− class (Lattice a) <= DistributiveLattice a
791− instance distributiveLatticeBoolean :: DistributiveLattice Boolean
793− -- | The `BooleanAlgebra` type class represents types that are Boolean
794− -- | algebras, also known as Boolean lattices.
796− -- | Instances should satisfy the `ComplementedLattice` and
797− -- | `DistributiveLattice` laws.
798− class (ComplementedLattice a, DistributiveLattice a) <= BooleanAlgebra a
800− instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
804− -- | The `sup` operator.
805− (||) :: forall a. (Lattice a) => a -> a -> a
810− -- | The `inf` operator.
811− (&&) :: forall a. (Lattice a) => a -> a -> a
814− foreign import boolAnd
816− function boolAnd(b1) {
817− return function(b2) {
821− """ :: Boolean -> Boolean -> Boolean
823− foreign import boolOr
825− function boolOr(b1) {
826− return function(b2) {
830− """ :: Boolean -> Boolean -> Boolean
832− foreign import boolNot
834− function boolNot(b) {
837− """ :: Boolean -> Boolean
841− -- | The `Semigroup` type class identifies an associative operation on a type.
843− -- | `Semigroup` instances are required to satisfy the following law:
845− -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
847− -- | For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
848− class Semigroup a where
851− foreign import concatString
853− function concatString(s1) {
854− return function(s2) {
858− """ :: String -> String -> String
860− instance semigroupUnit :: Semigroup Unit where
861− (<>) (Unit {}) (Unit {}) = Unit {}
863− instance semigroupString :: Semigroup String where
866− instance semigroupArr :: (Semigroup s') => Semigroup (s -> s') where
867− (<>) f g = \x -> f x <> g x
871− -- | `(++)` is an alias for `(<>)`.
872− (++) :: forall s. (Semigroup s) => s -> s -> s
879− -- | The `Bits` type class identifies types which support bitwise operations.
881− (.&.) :: b -> b -> b
882− (.|.) :: b -> b -> b
883− (.^.) :: b -> b -> b
884− shl :: b -> Number -> b
885− shr :: b -> Number -> b
886− zshr :: b -> Number -> b
887− complement :: b -> b
889− foreign import numShl
891− function numShl(n1) {
892− return function(n2) {
896− """ :: Number -> Number -> Number
898− foreign import numShr
900− function numShr(n1) {
901− return function(n2) {
905− """ :: Number -> Number -> Number
907− foreign import numZshr
909− function numZshr(n1) {
910− return function(n2) {
914− """ :: Number -> Number -> Number
916− foreign import numAnd
918− function numAnd(n1) {
919− return function(n2) {
923− """ :: Number -> Number -> Number
925− foreign import numOr
927− function numOr(n1) {
928− return function(n2) {
932− """ :: Number -> Number -> Number
934− foreign import numXor
936− function numXor(n1) {
937− return function(n2) {
941− """ :: Number -> Number -> Number
943− foreign import numComplement
945− function numComplement(n) {
948− """ :: Number -> Number
950− instance bitsNumber :: Bits Number where
957− complement = numComplement
959−module Data.Function where
961− -- | The `on` function is used to change the domain of a binary operator.
963− -- | For example, we can create a function which compares two records based on the values of their `x` properties:
966− -- | compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
967− -- | compareX = compare `on` _.x
969− on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
970− on f g x y = g x `f` g y
972− -- | A function of zero arguments
973− foreign import data Fn0 :: * -> *
975− -- | A function of one argument
976− foreign import data Fn1 :: * -> * -> *
978− -- | A function of two arguments
979− foreign import data Fn2 :: * -> * -> * -> *
981− -- | A function of three arguments
982− foreign import data Fn3 :: * -> * -> * -> * -> *
984− -- | A function of four arguments
985− foreign import data Fn4 :: * -> * -> * -> * -> * -> *
987− -- | A function of five arguments
988− foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
990− -- | A function of six arguments
991− foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
993− -- | A function of seven arguments
994− foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
996− -- | A function of eight arguments
997− foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
999− -- | A function of nine arguments
1000− foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
1002− -- | A function of ten arguments
1003− foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
1005− -- | Create a function of no arguments
1006− foreign import mkFn0
1008− function mkFn0(fn) {
1009− return function() {
1013− """ :: forall a. (Unit -> a) -> Fn0 a
1015− -- | Create a function of one argument
1016− foreign import mkFn1
1018− function mkFn1(fn) {
1019− return function(a) {
1023− """ :: forall a b. (a -> b) -> Fn1 a b
1025− -- | Create a function of two arguments from a curried function
1026− foreign import mkFn2
1028− function mkFn2(fn) {
1029− return function(a, b) {
1033− """ :: forall a b c. (a -> b -> c) -> Fn2 a b c
1035− -- | Create a function of three arguments from a curried function
1036− foreign import mkFn3
1038− function mkFn3(fn) {
1039− return function(a, b, c) {
1040− return fn(a)(b)(c);
1043− """ :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
1045− -- | Create a function of four arguments from a curried function
1046− foreign import mkFn4
1048− function mkFn4(fn) {
1049− return function(a, b, c, d) {
1050− return fn(a)(b)(c)(d);
1053− """ :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
1055− -- | Create a function of five arguments from a curried function
1056− foreign import mkFn5
1058− function mkFn5(fn) {
1059− return function(a, b, c, d, e) {
1060− return fn(a)(b)(c)(d)(e);
1063− """ :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
1065− -- | Create a function of six arguments from a curried function
1066− foreign import mkFn6
1068− function mkFn6(fn) {
1069− return function(a, b, c, d, e, f) {
1070− return fn(a)(b)(c)(d)(e)(f);
1073− """ :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
1075− -- | Create a function of seven arguments from a curried function
1076− foreign import mkFn7
1078− function mkFn7(fn) {
1079− return function(a, b, c, d, e, f, g) {
1080− return fn(a)(b)(c)(d)(e)(f)(g);
1083− """ :: 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
1085− -- | Create a function of eight arguments from a curried function
1086− foreign import mkFn8
1088− function mkFn8(fn) {
1089− return function(a, b, c, d, e, f, g, h) {
1090− return fn(a)(b)(c)(d)(e)(f)(g)(h);
1093− """ :: 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
1095− -- | Create a function of nine arguments from a curried function
1096− foreign import mkFn9
1098− function mkFn9(fn) {
1099− return function(a, b, c, d, e, f, g, h, i) {
1100− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i);
1103− """ :: 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
1105− -- | Create a function of ten arguments from a curried function
1106− foreign import mkFn10
1108− function mkFn10(fn) {
1109− return function(a, b, c, d, e, f, g, h, i, j) {
1110− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);
1113− """ :: 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
1115− -- | Apply a function of no arguments
1116− foreign import runFn0
1118− function runFn0(fn) {
1121− """ :: forall a. Fn0 a -> a
1123− -- | Apply a function of one argument
1124− foreign import runFn1
1126− function runFn1(fn) {
1127− return function(a) {
1131− """ :: forall a b. Fn1 a b -> a -> b
1133− -- | Apply a function of two arguments
1134− foreign import runFn2
1136− function runFn2(fn) {
1137− return function(a) {
1138− return function(b) {
1143− """ :: forall a b c. Fn2 a b c -> a -> b -> c
1145− -- | Apply a function of three arguments
1146− foreign import runFn3
1148− function runFn3(fn) {
1149− return function(a) {
1150− return function(b) {
1151− return function(c) {
1152− return fn(a, b, c);
1157− """ :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
1159− -- | Apply a function of four arguments
1160− foreign import runFn4
1162− function runFn4(fn) {
1163− return function(a) {
1164− return function(b) {
1165− return function(c) {
1166− return function(d) {
1167− return fn(a, b, c, d);
1173− """ :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
1175− -- | Apply a function of five arguments
1176− foreign import runFn5
1178− function runFn5(fn) {
1179− return function(a) {
1180− return function(b) {
1181− return function(c) {
1182− return function(d) {
1183− return function(e) {
1184− return fn(a, b, c, d, e);
1191− """ :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
1193− -- | Apply a function of six arguments
1194− foreign import runFn6
1196− function runFn6(fn) {
1197− return function(a) {
1198− return function(b) {
1199− return function(c) {
1200− return function(d) {
1201− return function(e) {
1202− return function(f) {
1203− return fn(a, b, c, d, e, f);
1211− """ :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
1213− -- | Apply a function of seven arguments
1214− foreign import runFn7
1216− function runFn7(fn) {
1217− return function(a) {
1218− return function(b) {
1219− return function(c) {
1220− return function(d) {
1221− return function(e) {
1222− return function(f) {
1223− return function(g) {
1224− return fn(a, b, c, d, e, f, g);
1233− """ :: 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
1235− -- | Apply a function of eight arguments
1236− foreign import runFn8
1238− function runFn8(fn) {
1239− return function(a) {
1240− return function(b) {
1241− return function(c) {
1242− return function(d) {
1243− return function(e) {
1244− return function(f) {
1245− return function(g) {
1246− return function(h) {
1247− return fn(a, b, c, d, e, f, g, h);
1257− """ :: 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
1259− -- | Apply a function of nine arguments
1260− foreign import runFn9
1262− function runFn9(fn) {
1263− return function(a) {
1264− return function(b) {
1265− return function(c) {
1266− return function(d) {
1267− return function(e) {
1268− return function(f) {
1269− return function(g) {
1270− return function(h) {
1271− return function(i) {
1272− return fn(a, b, c, d, e, f, g, h, i);
1283− """ :: 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
1285− -- | Apply a function of ten arguments
1286− foreign import runFn10
1288− function runFn10(fn) {
1289− return function(a) {
1290− return function(b) {
1291− return function(c) {
1292− return function(d) {
1293− return function(e) {
1294− return function(f) {
1295− return function(g) {
1296− return function(h) {
1297− return function(i) {
1298− return function(j) {
1299− return fn(a, b, c, d, e, f, g, h, i, j);
1311− """ :: 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
1313−module Prelude.Unsafe where
1315− -- | Find the element of an array at the specified index.
1317− -- | Note: this function can cause unpredictable failure at runtime if the index is out-of-bounds.
1318− foreign import unsafeIndex
1320− function unsafeIndex(xs) {
1321− return function(n) {
1325− """ :: forall a. [a] -> Number -> a
1327−module Control.Monad.Eff
1331− , untilE, whileE, forE, foreachE
1334− -- | The `Eff` type constructor is used to represent _native_ effects.
1336− -- | See [Handling Native Effects with the Eff Monad](https://github.com/purescript/purescript/wiki/Handling-Native-Effects-with-the-Eff-Monad) for more details.
1338− -- | 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.
1339− foreign import data Eff :: # ! -> * -> *
1341− foreign import returnE
1343− function returnE(a) {
1344− return function() {
1348− """ :: forall e a. a -> Eff e a
1350− foreign import bindE
1352− function bindE(a) {
1353− return function(f) {
1354− return function() {
1359− """ :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
1361− -- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled.
1363− -- | The `runPure` function can be used to run pure computations and obtain their result.
1364− type Pure a = forall e. Eff e a
1366− -- | Run a pure computation and return its result.
1368− -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1369− -- | is to use parentheses instead.
1370− foreign import runPure
1372− function runPure(f) {
1375− """ :: forall a. Pure a -> a
1377− instance functorEff :: Functor (Eff e) where
1380− instance applyEff :: Apply (Eff e) where
1383− instance applicativeEff :: Applicative (Eff e) where
1386− instance bindEff :: Bind (Eff e) where
1389− instance monadEff :: Monad (Eff e)
1391− -- | Loop until a condition becomes `true`.
1393− -- | `untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
1394− -- | until its return value is `true`.
1395− foreign import untilE
1397− function untilE(f) {
1398− return function() {
1403− """ :: forall e. Eff e Boolean -> Eff e Unit
1405− -- | Loop while a condition is `true`.
1407− -- | `whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
1408− -- | `true`, it runs the effectful computation `m` and loops. If not, the computation ends.
1409− foreign import whileE
1411− function whileE(f) {
1412− return function(a) {
1413− return function() {
1421− """ :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
1423− -- | Loop over a consecutive collection of numbers.
1425− -- | `forE lo hi f` runs the computation returned by the function `f` for each of the inputs
1426− -- | between `lo` (inclusive) and `hi` (exclusive).
1427− foreign import forE
1429− function forE(lo) {
1430− return function(hi) {
1431− return function(f) {
1432− return function() {
1433− for (var i = lo; i < hi; i++) {
1440− """ :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
1442− -- | Loop over an array of values.
1444− -- | `foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`.
1445− foreign import foreachE
1447− function foreachE(as) {
1448− return function(f) {
1449− return function() {
1450− for (var i = 0; i < as.length; i++) {
1456− """ :: forall e a. [a] -> (a -> Eff e Unit) -> Eff e Unit
1458−module Control.Monad.Eff.Unsafe where
1460− import Control.Monad.Eff
1462− -- | Change the type of an effectful computation, allowing it to be run in another context.
1464− -- | Note: use of this function can result in arbitrary side-effects.
1465− foreign import unsafeInterleaveEff
1467− function unsafeInterleaveEff(f) {
1470− """ :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
1472−module Debug.Trace where
1474− import Control.Monad.Eff
1476− -- | The `Trace` effect represents those computations which write to the console.
1477− foreign import data Trace :: !
1479− -- | Write a `String` to the console.
1480− foreign import trace
1482− function trace(s) {
1483− return function() {
1488− """ :: forall r. String -> Eff (trace :: Trace | r) Unit
1490− -- | Write a value to the console, using its `Show` instance to produce a `String`.
1491− print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
1492− print o = trace (show o)
1494−module Control.Monad.ST where
1496− import Control.Monad.Eff
1498− -- | The `ST` effect represents _local mutation_, i.e. mutation which does not "escape" into the surrounding computation.
1500− -- | An `ST` computation is parameterized by a phantom type which is used to restrict the set of reference cells it is allowed to access.
1502− -- | The `runST` function can be used to handle the `ST` effect.
1503− foreign import data ST :: * -> !
1505− -- | The type `STRef s a` represents a mutable reference holding a value of type `a`, which can be used with the `ST s` effect.
1506− foreign import data STRef :: * -> * -> *
1508− -- | Create a new mutable reference.
1509− foreign import newSTRef
1511− function newSTRef(val) {
1512− return function() {
1513− return { value: val };
1516− """ :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1518− -- | Read the current value of a mutable reference.
1519− foreign import readSTRef
1521− function readSTRef(ref) {
1522− return function() {
1526− """ :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1528− -- | Modify the value of a mutable reference by applying a function to the current value.
1529− foreign import modifySTRef
1531− function modifySTRef(ref) {
1532− return function(f) {
1533− return function() {
1534− return ref.value = f(ref.value);
1538− """ :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1540− -- | Set the value of a mutable reference.
1541− foreign import writeSTRef
1543− function writeSTRef(ref) {
1544− return function(a) {
1545− return function() {
1546− return ref.value = a;
1550− """ :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1552− -- | Run an `ST` computation.
1554− -- | 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
1555− -- | to the surrounding computation.
1557− -- | It may cause problems to apply this function using the `$` operator. The recommended approach is to use parentheses instead.
1558− foreign import runST
1560− function runST(f) {
1563− """ :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1565− -- | A convenience function which combines `runST` with `runPure`, which can be used when the only required effect is `ST`.
1567− -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1568− -- | is to use parentheses instead.
1569− pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
1570− pureST st = runPure (runST st)