@@ -0,0 +1,1478 @@
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+ , Bits, (.&.), (.|.), (.^.), shl, shr, zshr, complement
26+ , BoolLike, (&&), (||)
28+ , Semigroup, (<>), (++)
32+ -- | An alias for `true`, which can be useful in guard clauses:
35+ -- | max x y | x >= y = x
42+ -- | Flips the order of the arguments to a function of two arguments.
45+ -- | flip const 1 2 = const 2 1 = 2
48+ flip :: forall a b c. (a -> b -> c) -> b -> a -> c
51+ -- | Returns its first argument and ignores its second.
54+ -- | const 1 "hello" = 1
57+ const :: forall a b. a -> b -> a
60+ -- | This function returns its first argument, and can be used to assert type equalities.
61+ -- | This can be useful when types are otherwise ambiguous.
64+ -- | main = print $ [] `asTypeOf` [0]
67+ -- | If instead, we had written `main = print []`, the type of the argument `[]` would have
68+ -- | been ambiguous, resulting in a compile-time error.
69+ asTypeOf :: forall a. a -> a -> a
75+ -- | A `Semigroupoid` is similar to a [`Category`](#category) but does not require an identity
76+ -- | element `id`, just composable morphisms.
78+ -- | `Semigroupoid`s should obey the following rule:
80+ -- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
82+ -- | One example of a `Semigroupoid` is the function type constructor `(->)`, with `(<<<)` defined
83+ -- | as function composition.
84+ class Semigroupoid a where
85+ (<<<) :: forall b c d. a c d -> a b c -> a b d
87+ instance semigroupoidArr :: Semigroupoid (->) where
88+ (<<<) f g x = f (g x)
90+ -- | Forwards composition, or `(<<<)` with its arguments reversed.
91+ (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
94+ -- | `Category`s consist of objects and composable morphisms between them, and as such are
95+ -- | [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids` must have an identity element.
97+ -- | `Category`s should obey the following rules.
99+ -- | - Left Identity: `id <<< p = p`
100+ -- | - Right Identity: `p <<< id = p`
102+ class (Semigroupoid a) <= Category a where
103+ id :: forall t. a t t
105+ instance categoryArr :: Category (->) where
111+ -- | Applies a function to its argument
114+ -- | length $ groupBy productCategory $ filter isInStock products
117+ -- | is equivalent to
120+ -- | length (groupBy productCategory (filter isInStock (products)))
123+ -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
124+ -- | `a $ b $ c $ d x` = `a $ (b $ (c $ (d $ x)))` = `a (b (c (d x)))`
126+ ($) :: forall a b. (a -> b) -> a -> b
129+ -- | Applies a function to its argument
132+ -- | products # groupBy productCategory # filter isInStock # length
135+ -- | is equivalent to
138+ -- | length (filter isInStock (groupBy productCategory (products)))
141+ -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
142+ -- | `x # a # b # c # d` = `(((x # a) # b) # c) # d` = `d (c (b (a x)))`
144+ (#) :: forall a b. a -> (a -> b) -> b
149+ -- | An infix alias for `cons`.
151+ -- | Note, the running time of this function is `O(n)`.
152+ (:) :: forall a. a -> [a] -> [a]
155+ -- | Attaches an element to the front of an array, creating a new array.
158+ -- | cons 1 [2, 3, 4] = [1, 2, 3, 4]
161+ -- | Note, the running time of this function is `O(n)`.
165+ return function(l) {
166+ return [e].concat(l);
169+ """ :: forall a. a -> [a] -> [a]
171+ -- | The `Show` type class represents those types which can be converted into a human-readable `String` representation.
173+ -- | While not required, it is recommended that for any expression `x`, the string `show x` be executable PureScript code
174+ -- | which evaluates to the same value as the expression `x`.
178+ foreign import showStringImpl
180+ function showStringImpl(s) {
181+ return JSON.stringify(s);
183+ """ :: String -> String
185+ instance showUnit :: Show Unit where
186+ show (Unit {}) = "Unit {}"
188+ instance showString :: Show String where
189+ show = showStringImpl
191+ instance showBoolean :: Show Boolean where
193+ show false = "false"
195+ foreign import showNumberImpl
197+ function showNumberImpl(n) {
198+ return n.toString();
200+ """ :: Number -> String
202+ instance showNumber :: Show Number where
203+ show = showNumberImpl
205+ foreign import showArrayImpl
207+ function showArrayImpl(f) {
208+ return function(xs) {
210+ for (var i = 0, l = xs.length; i < l; i++) {
213+ return '[' + ss.join(',') + ']';
216+ """ :: forall a. (a -> String) -> [a] -> String
218+ instance showArray :: (Show a) => Show [a] where
219+ show = showArrayImpl show
224+ -- | A `Functor` is a type constructor which supports a mapping operation `(<$>)`.
226+ -- | `(<$>)` can be used to turn functions `a -> b` into functions `f a -> f b` whose argument and return
227+ -- | types use the type constructor `f` to represent some computational context.
229+ -- | `Functor` instances should satisfy the following laws:
231+ -- | - Identity: `(<$>) id = id`
232+ -- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
234+ class Functor f where
235+ (<$>) :: forall a b. (a -> b) -> f a -> f b
237+ -- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
240+ -- | [1, 2, 3] <#> \n -> n * n
242+ (<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
243+ (<#>) fa f = f <$> fa
245+ -- | The `void` function is used to ignore the type wrapped by a [`Functor`](#functor), replacing it with `Unit` and
246+ -- | keeping only the type information provided by the type constructor itself.
248+ -- | `void` is often useful when using `do` notation to change the return type of a monadic computation:
251+ -- | main = forE 1 10 \n -> void do
255+ void :: forall f a. (Functor f) => f a -> f Unit
256+ void fa = const unit <$> fa
260+ -- | The `Apply` class provides the `(<*>)` which is used to apply a function to an argument under a type constructor.
262+ -- | `Apply` can be used to lift functions of two or more arguments to work on values wrapped with the type constructor `f`.
263+ -- | It might also be understood in terms of the `lift2` function:
266+ -- | lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
267+ -- | lift2 f a b = f <$> a <*> b
270+ -- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts the function application operator `($)` to arguments
271+ -- | wrapped with the type constructor `f`.
273+ -- | `Apply` instances should satisfy the following law:
275+ -- | - Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
277+ -- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
278+ class (Functor f) <= Apply f where
279+ (<*>) :: forall a b. f (a -> b) -> f a -> f b
281+ -- | The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
282+ -- | create values of type `f a` from values of type `a`.
284+ -- | Where [`Apply`](#apply) provides the ability to lift functions of two or more arguments to functions whose arguments are wrapped using `f`,
285+ -- | and [`Functor`](#functor) provides the ability to lift functions of one argument, `pure` can be seen as the function which lifts functions of
286+ -- | _zero_ arguments. That is, `Applicative` functors support a lifting operation for any number of function arguments.
288+ -- | `Applicative` instances should satisfy the following laws:
290+ -- | - Identity: `(pure id) <*> v = v`
291+ -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
292+ -- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
293+ -- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
295+ class (Apply f) <= Applicative f where
296+ pure :: forall a. a -> f a
298+ -- | `liftA1` provides a default implementation of `(<$>)` for any [`Applicative`](#applicative) functor,
299+ -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass relationship.
301+ -- | `liftA1` can therefore be used to write [`Functor`](#functor) instances as follows:
304+ -- | instance functorF :: Functor F where
307+ liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
308+ liftA1 f a = pure f <*> a
312+ -- | The `Bind` type class extends the [`Apply`](#apply) type class with a "bind" operation `(>>=)` which composes computations
313+ -- | in sequence, using the return value of one computation to determine the next computation.
315+ -- | The `>>=` operator can also be expressed using `do` notation, as follows:
318+ -- | x >>= f = do y <- x
322+ -- | where the function argument of `f` is given the name `y`.
324+ -- | `Bind` instances should satisfy the following law:
326+ -- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
328+ -- | Or, expressed using `do` notation:
330+ -- | - Associativity: `do { z <- do { y <- x ; f y } ; g z } = do { k <- x ; do { y <- f k ; g y } }`
332+ -- | Associativity tells us that we can regroup operations which use do-notation, so that we can unambiguously write, for example:
339+ class (Apply m) <= Bind m where
340+ (>>=) :: forall a b. m a -> (a -> m b) -> m b
342+ -- | The `Monad` type class combines the operations of the `Bind` and `Applicative` type classes. Therefore, `Monad` instances
343+ -- | represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
345+ -- | `Monad` instances should satisfy the following laws:
347+ -- | - Left Identity: `pure x >>= f = f x`
348+ -- | - Right Identity: `x >>= pure = x`
350+ -- | Or, expressed using `do` notation:
352+ -- | - Left Identity: `do { y <- pure x ; f y } = f x`
353+ -- | - Right Identity: `do { y <- x ; pure y } = x`
355+ class (Applicative m, Bind m) <= Monad m
357+ -- | `return` is an alias for `pure`.
358+ return :: forall m a. (Monad m) => a -> m a
361+ -- | `liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
362+ -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
364+ -- | `liftM1` can therefore be used to write [`Functor`](#functor) instances as follows:
367+ -- | instance functorF :: Functor F where
370+ liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
375+ -- | `ap` provides a default implementation of `(<*>)` for any [`Monad`](#monad),
376+ -- | without using `(<*>)` as provided by the [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
378+ -- | `ap` can therefore be used to write [`Apply`](#apply) instances as follows:
381+ -- | instance applyF :: Apply F where
384+ ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
390+ instance functorArr :: Functor ((->) r) where
393+ instance applyArr :: Apply ((->) r) where
394+ (<*>) f g x = f x (g x)
396+ instance applicativeArr :: Applicative ((->) r) where
399+ instance bindArr :: Bind ((->) r) where
400+ (>>=) m f x = f (m x) x
402+ instance monadArr :: Monad ((->) r)
411+ -- | Addition and multiplication, satisfying the following laws:
413+ -- | - `a` is a commutative monoid under addition
414+ -- | - `a` is a monoid under multiplication
415+ -- | - multiplication distributes over addition
416+ -- | - multiplication by `zero` annihilates `a`
418+ class Semiring a where
424+ -- | Addition, multiplication, modulo operation and division, satisfying:
426+ -- | - ```a / b * b + (a `mod` b) = a```
428+ class (Semiring a) <= ModuloSemiring a where
432+ -- | Addition, multiplication, and subtraction.
434+ -- | Has the same laws as `Semiring` but additionally satisfying:
436+ -- | - `a` is an abelian group under addition
438+ class (Semiring a) <= Ring a where
441+ negate :: forall a. (Ring a) => a -> a
444+ -- | Ring where every nonzero element has a multiplicative inverse so that:
446+ -- | - ```a `mod` b = zero```
448+ class (Ring a, ModuloSemiring a) <= DivisionRing a
450+ -- | A commutative field
451+ class (DivisionRing a) <= Num a
453+ foreign import numAdd
455+ function numAdd(n1) {
456+ return function(n2) {
460+ """ :: Number -> Number -> Number
462+ foreign import numSub
464+ function numSub(n1) {
465+ return function(n2) {
469+ """ :: Number -> Number -> Number
471+ foreign import numMul
473+ function numMul(n1) {
474+ return function(n2) {
478+ """ :: Number -> Number -> Number
480+ foreign import numDiv
482+ function numDiv(n1) {
483+ return function(n2) {
487+ """ :: Number -> Number -> Number
489+ foreign import numMod
491+ function numMod(n1) {
492+ return function(n2) {
496+ """ :: Number -> Number -> Number
500+ instance semiringNumber :: Semiring Number where
506+ instance ringNumber :: Ring Number where
509+ instance moduloSemiringNumber :: ModuloSemiring Number where
513+ instance divisionRingNumber :: DivisionRing Number
515+ instance numNumber :: Num Number
517+ -- | The `Unit` type has a single inhabitant, called `unit`. It represents values with no computational content.
519+ -- | `Unit` is often used, wrapped in a monadic type constructor, as the return type of a computation where only
520+ -- | the _effects_ are important.
521+ newtype Unit = Unit {}
523+ -- | `unit` is the sole inhabitant of the `Unit` type.
530+ -- | The `Eq` type class represents types which support decidable equality.
532+ -- | `Eq` instances should satisfy the following laws:
534+ -- | - Reflexivity: `x == x = true`
535+ -- | - Symmetry: `x == y = y == x`
536+ -- | - Transitivity: if `x == y` and `y == z` then `x == z`
537+ -- | - Negation: `x /= y = not (x == y)`
539+ -- | `(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
541+ (==) :: a -> a -> Boolean
542+ (/=) :: a -> a -> Boolean
544+ foreign import refEq
546+ function refEq(r1) {
547+ return function(r2) {
551+ """ :: forall a. a -> a -> Boolean
553+ foreign import refIneq
555+ function refIneq(r1) {
556+ return function(r2) {
560+ """ :: forall a. a -> a -> Boolean
562+ instance eqUnit :: Eq Unit where
563+ (==) (Unit {}) (Unit {}) = true
564+ (/=) (Unit {}) (Unit {}) = false
566+ instance eqString :: Eq String where
570+ instance eqNumber :: Eq Number where
574+ instance eqBoolean :: Eq Boolean where
578+ foreign import eqArrayImpl
580+ function eqArrayImpl(f) {
581+ return function(xs) {
582+ return function(ys) {
583+ if (xs.length !== ys.length) return false;
584+ for (var i = 0; i < xs.length; i++) {
585+ if (!f(xs[i])(ys[i])) return false;
591+ """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
593+ instance eqArray :: (Eq a) => Eq [a] where
594+ (==) xs ys = eqArrayImpl (==) xs ys
595+ (/=) xs ys = not (xs == ys)
597+ -- | The `Ordering` data type represents the three possible outcomes of comparing two values:
599+ -- | `LT` - The first value is _less than_ the second.
600+ -- | `GT` - The first value is _greater than_ the second.
601+ -- | `EQ` - The first value is _equal to_ or _incomparable to_ the second.
602+ data Ordering = LT | GT | EQ
604+ instance eqOrdering :: Eq Ordering where
609+ (/=) x y = not (x == y)
611+ instance showOrdering :: Show Ordering where
616+ instance semigroupOrdering :: Semigroup Ordering where
621+ -- | The `Ord` type class represents types which support comparisons.
623+ -- | `Ord` instances should satisfy the laws of _partially orderings_:
625+ -- | - Reflexivity: `a <= a`
626+ -- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
627+ -- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
629+ class (Eq a) <= Ord a where
630+ compare :: a -> a -> Ordering
634+ -- | Test whether one value is _strictly less than_ another.
635+ (<) :: forall a. (Ord a) => a -> a -> Boolean
636+ (<) a1 a2 = case a1 `compare` a2 of
642+ -- | Test whether one value is _strictly greater than_ another.
643+ (>) :: forall a. (Ord a) => a -> a -> Boolean
644+ (>) a1 a2 = case a1 `compare` a2 of
650+ -- | Test whether one value is _non-strictly less than_ another.
651+ (<=) :: forall a. (Ord a) => a -> a -> Boolean
652+ (<=) a1 a2 = case a1 `compare` a2 of
658+ -- | Test whether one value is _non-strictly greater than_ another.
659+ (>=) :: forall a. (Ord a) => a -> a -> Boolean
660+ (>=) a1 a2 = case a1 `compare` a2 of
664+ foreign import unsafeCompareImpl
666+ function unsafeCompareImpl(lt) {
667+ return function(eq) {
668+ return function(gt) {
669+ return function(x) {
670+ return function(y) {
671+ return x < y ? lt : x > y ? gt : eq;
677+ """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
679+ unsafeCompare :: forall a. a -> a -> Ordering
680+ unsafeCompare = unsafeCompareImpl LT EQ GT
682+ instance ordUnit :: Ord Unit where
683+ compare (Unit {}) (Unit {}) = EQ
685+ instance ordBoolean :: Ord Boolean where
686+ compare false false = EQ
687+ compare false true = LT
688+ compare true true = EQ
689+ compare true false = GT
691+ instance ordNumber :: Ord Number where
692+ compare = unsafeCompare
694+ instance ordString :: Ord String where
695+ compare = unsafeCompare
697+ instance ordArray :: (Ord a) => Ord [a] where
701+ compare (x:xs) (y:ys) = case compare x y of
709+ -- | The `Bits` type class identifies types which support bitwise operations.
711+ (.&.) :: b -> b -> b
712+ (.|.) :: b -> b -> b
713+ (.^.) :: b -> b -> b
714+ shl :: b -> Number -> b
715+ shr :: b -> Number -> b
716+ zshr :: b -> Number -> b
717+ complement :: b -> b
719+ foreign import numShl
721+ function numShl(n1) {
722+ return function(n2) {
726+ """ :: Number -> Number -> Number
728+ foreign import numShr
730+ function numShr(n1) {
731+ return function(n2) {
735+ """ :: Number -> Number -> Number
737+ foreign import numZshr
739+ function numZshr(n1) {
740+ return function(n2) {
744+ """ :: Number -> Number -> Number
746+ foreign import numAnd
748+ function numAnd(n1) {
749+ return function(n2) {
753+ """ :: Number -> Number -> Number
755+ foreign import numOr
757+ function numOr(n1) {
758+ return function(n2) {
762+ """ :: Number -> Number -> Number
764+ foreign import numXor
766+ function numXor(n1) {
767+ return function(n2) {
771+ """ :: Number -> Number -> Number
773+ foreign import numComplement
775+ function numComplement(n) {
778+ """ :: Number -> Number
780+ instance bitsNumber :: Bits Number where
787+ complement = numComplement
792+ -- | The `BoolLike` type class identifies types which support Boolean operations.
794+ -- | `BoolLike` instances are required to satisfy the laws of a _Boolean algebra_.
796+ class BoolLike b where
801+ foreign import boolAnd
803+ function boolAnd(b1) {
804+ return function(b2) {
808+ """ :: Boolean -> Boolean -> Boolean
810+ foreign import boolOr
812+ function boolOr(b1) {
813+ return function(b2) {
817+ """ :: Boolean -> Boolean -> Boolean
819+ foreign import boolNot
821+ function boolNot(b) {
824+ """ :: Boolean -> Boolean
826+ instance boolLikeBoolean :: BoolLike Boolean where
833+ -- | The `Semigroup` type class identifies an associative operation on a type.
835+ -- | `Semigroup` instances are required to satisfy the following law:
837+ -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
839+ -- | For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
840+ class Semigroup a where
843+ foreign import concatString
845+ function concatString(s1) {
846+ return function(s2) {
850+ """ :: String -> String -> String
852+ instance semigroupUnit :: Semigroup Unit where
853+ (<>) (Unit {}) (Unit {}) = Unit {}
855+ instance semigroupString :: Semigroup String where
858+ instance semigroupArr :: (Semigroup s') => Semigroup (s -> s') where
859+ (<>) f g = \x -> f x <> g x
863+ -- | `(++)` is an alias for `(<>)`.
864+ (++) :: forall s. (Semigroup s) => s -> s -> s
867+module Data.Function where
869+ -- | The `on` function is used to change the domain of a binary operator.
871+ -- | For example, we can create a function which compares two records based on the values of their `x` properties:
874+ -- | compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
875+ -- | compareX = compare `on` _.x
877+ on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
878+ on f g x y = g x `f` g y
880+ -- | A function of zero arguments
881+ foreign import data Fn0 :: * -> *
883+ -- | A function of one argument
884+ foreign import data Fn1 :: * -> * -> *
886+ -- | A function of two arguments
887+ foreign import data Fn2 :: * -> * -> * -> *
889+ -- | A function of three arguments
890+ foreign import data Fn3 :: * -> * -> * -> * -> *
892+ -- | A function of four arguments
893+ foreign import data Fn4 :: * -> * -> * -> * -> * -> *
895+ -- | A function of five arguments
896+ foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
898+ -- | A function of six arguments
899+ foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
901+ -- | A function of seven arguments
902+ foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
904+ -- | A function of eight arguments
905+ foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
907+ -- | A function of nine arguments
908+ foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
910+ -- | A function of ten arguments
911+ foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
913+ -- | Create a function of no arguments
914+ foreign import mkFn0
916+ function mkFn0(fn) {
921+ """ :: forall a. (Unit -> a) -> Fn0 a
923+ -- | Create a function of one argument
924+ foreign import mkFn1
926+ function mkFn1(fn) {
927+ return function(a) {
931+ """ :: forall a b. (a -> b) -> Fn1 a b
933+ -- | Create a function of two arguments from a curried function
934+ foreign import mkFn2
936+ function mkFn2(fn) {
937+ return function(a, b) {
941+ """ :: forall a b c. (a -> b -> c) -> Fn2 a b c
943+ -- | Create a function of three arguments from a curried function
944+ foreign import mkFn3
946+ function mkFn3(fn) {
947+ return function(a, b, c) {
951+ """ :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
953+ -- | Create a function of four arguments from a curried function
954+ foreign import mkFn4
956+ function mkFn4(fn) {
957+ return function(a, b, c, d) {
958+ return fn(a)(b)(c)(d);
961+ """ :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
963+ -- | Create a function of five arguments from a curried function
964+ foreign import mkFn5
966+ function mkFn5(fn) {
967+ return function(a, b, c, d, e) {
968+ return fn(a)(b)(c)(d)(e);
971+ """ :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
973+ -- | Create a function of six arguments from a curried function
974+ foreign import mkFn6
976+ function mkFn6(fn) {
977+ return function(a, b, c, d, e, f) {
978+ return fn(a)(b)(c)(d)(e)(f);
981+ """ :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
983+ -- | Create a function of seven arguments from a curried function
984+ foreign import mkFn7
986+ function mkFn7(fn) {
987+ return function(a, b, c, d, e, f, g) {
988+ return fn(a)(b)(c)(d)(e)(f)(g);
991+ """ :: 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
993+ -- | Create a function of eight arguments from a curried function
994+ foreign import mkFn8
996+ function mkFn8(fn) {
997+ return function(a, b, c, d, e, f, g, h) {
998+ return fn(a)(b)(c)(d)(e)(f)(g)(h);
1001+ """ :: 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
1003+ -- | Create a function of nine arguments from a curried function
1004+ foreign import mkFn9
1006+ function mkFn9(fn) {
1007+ return function(a, b, c, d, e, f, g, h, i) {
1008+ return fn(a)(b)(c)(d)(e)(f)(g)(h)(i);
1011+ """ :: 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
1013+ -- | Create a function of ten arguments from a curried function
1014+ foreign import mkFn10
1016+ function mkFn10(fn) {
1017+ return function(a, b, c, d, e, f, g, h, i, j) {
1018+ return fn(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);
1021+ """ :: 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
1023+ -- | Apply a function of no arguments
1024+ foreign import runFn0
1026+ function runFn0(fn) {
1029+ """ :: forall a. Fn0 a -> a
1031+ -- | Apply a function of one argument
1032+ foreign import runFn1
1034+ function runFn1(fn) {
1035+ return function(a) {
1039+ """ :: forall a b. Fn1 a b -> a -> b
1041+ -- | Apply a function of two arguments
1042+ foreign import runFn2
1044+ function runFn2(fn) {
1045+ return function(a) {
1046+ return function(b) {
1051+ """ :: forall a b c. Fn2 a b c -> a -> b -> c
1053+ -- | Apply a function of three arguments
1054+ foreign import runFn3
1056+ function runFn3(fn) {
1057+ return function(a) {
1058+ return function(b) {
1059+ return function(c) {
1060+ return fn(a, b, c);
1065+ """ :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
1067+ -- | Apply a function of four arguments
1068+ foreign import runFn4
1070+ function runFn4(fn) {
1071+ return function(a) {
1072+ return function(b) {
1073+ return function(c) {
1074+ return function(d) {
1075+ return fn(a, b, c, d);
1081+ """ :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
1083+ -- | Apply a function of five arguments
1084+ foreign import runFn5
1086+ function runFn5(fn) {
1087+ return function(a) {
1088+ return function(b) {
1089+ return function(c) {
1090+ return function(d) {
1091+ return function(e) {
1092+ return fn(a, b, c, d, e);
1099+ """ :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
1101+ -- | Apply a function of six arguments
1102+ foreign import runFn6
1104+ function runFn6(fn) {
1105+ return function(a) {
1106+ return function(b) {
1107+ return function(c) {
1108+ return function(d) {
1109+ return function(e) {
1110+ return function(f) {
1111+ return fn(a, b, c, d, e, f);
1119+ """ :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
1121+ -- | Apply a function of seven arguments
1122+ foreign import runFn7
1124+ function runFn7(fn) {
1125+ return function(a) {
1126+ return function(b) {
1127+ return function(c) {
1128+ return function(d) {
1129+ return function(e) {
1130+ return function(f) {
1131+ return function(g) {
1132+ return fn(a, b, c, d, e, f, g);
1141+ """ :: 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
1143+ -- | Apply a function of eight arguments
1144+ foreign import runFn8
1146+ function runFn8(fn) {
1147+ return function(a) {
1148+ return function(b) {
1149+ return function(c) {
1150+ return function(d) {
1151+ return function(e) {
1152+ return function(f) {
1153+ return function(g) {
1154+ return function(h) {
1155+ return fn(a, b, c, d, e, f, g, h);
1165+ """ :: 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
1167+ -- | Apply a function of nine arguments
1168+ foreign import runFn9
1170+ function runFn9(fn) {
1171+ return function(a) {
1172+ return function(b) {
1173+ return function(c) {
1174+ return function(d) {
1175+ return function(e) {
1176+ return function(f) {
1177+ return function(g) {
1178+ return function(h) {
1179+ return function(i) {
1180+ return fn(a, b, c, d, e, f, g, h, i);
1191+ """ :: 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
1193+ -- | Apply a function of ten arguments
1194+ foreign import runFn10
1196+ function runFn10(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 function(g) {
1204+ return function(h) {
1205+ return function(i) {
1206+ return function(j) {
1207+ return fn(a, b, c, d, e, f, g, h, i, j);
1219+ """ :: 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
1221+module Prelude.Unsafe where
1223+ -- | Find the element of an array at the specified index.
1225+ -- | Note: this function can cause unpredictable failure at runtime if the index is out-of-bounds.
1226+ foreign import unsafeIndex
1228+ function unsafeIndex(xs) {
1229+ return function(n) {
1233+ """ :: forall a. [a] -> Number -> a
1235+module Control.Monad.Eff
1239+ , untilE, whileE, forE, foreachE
1242+ -- | The `Eff` type constructor is used to represent _native_ effects.
1244+ -- | See [Handling Native Effects with the Eff Monad](https://github.com/purescript/purescript/wiki/Handling-Native-Effects-with-the-Eff-Monad) for more details.
1246+ -- | 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.
1247+ foreign import data Eff :: # ! -> * -> *
1249+ foreign import returnE
1251+ function returnE(a) {
1252+ return function() {
1256+ """ :: forall e a. a -> Eff e a
1258+ foreign import bindE
1260+ function bindE(a) {
1261+ return function(f) {
1262+ return function() {
1267+ """ :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
1269+ -- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled.
1271+ -- | The `runPure` function can be used to run pure computations and obtain their result.
1272+ type Pure a = forall e. Eff e a
1274+ -- | Run a pure computation and return its result.
1276+ -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1277+ -- | is to use parentheses instead.
1278+ foreign import runPure
1280+ function runPure(f) {
1283+ """ :: forall a. Pure a -> a
1285+ instance functorEff :: Functor (Eff e) where
1288+ instance applyEff :: Apply (Eff e) where
1291+ instance applicativeEff :: Applicative (Eff e) where
1294+ instance bindEff :: Bind (Eff e) where
1297+ instance monadEff :: Monad (Eff e)
1299+ -- | Loop until a condition becomes `true`.
1301+ -- | `untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
1302+ -- | until its return value is `true`.
1303+ foreign import untilE
1305+ function untilE(f) {
1306+ return function() {
1311+ """ :: forall e. Eff e Boolean -> Eff e Unit
1313+ -- | Loop while a condition is `true`.
1315+ -- | `whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
1316+ -- | `true`, it runs the effectful computation `m` and loops. If not, the computation ends.
1317+ foreign import whileE
1319+ function whileE(f) {
1320+ return function(a) {
1321+ return function() {
1329+ """ :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
1331+ -- | Loop over a consecutive collection of numbers.
1333+ -- | `forE lo hi f` runs the computation returned by the function `f` for each of the inputs
1334+ -- | between `lo` (inclusive) and `hi` (exclusive).
1335+ foreign import forE
1337+ function forE(lo) {
1338+ return function(hi) {
1339+ return function(f) {
1340+ return function() {
1341+ for (var i = lo; i < hi; i++) {
1348+ """ :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
1350+ -- | Loop over an array of values.
1352+ -- | `foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`.
1353+ foreign import foreachE
1355+ function foreachE(as) {
1356+ return function(f) {
1357+ return function() {
1358+ for (var i = 0; i < as.length; i++) {
1364+ """ :: forall e a. [a] -> (a -> Eff e Unit) -> Eff e Unit
1366+module Control.Monad.Eff.Unsafe where
1368+ import Control.Monad.Eff
1370+ -- | Change the type of an effectful computation, allowing it to be run in another context.
1372+ -- | Note: use of this function can result in arbitrary side-effects.
1373+ foreign import unsafeInterleaveEff
1375+ function unsafeInterleaveEff(f) {
1378+ """ :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
1380+module Debug.Trace where
1382+ import Control.Monad.Eff
1384+ -- | The `Trace` effect represents those computations which write to the console.
1385+ foreign import data Trace :: !
1387+ -- | Write a `String` to the console.
1388+ foreign import trace
1390+ function trace(s) {
1391+ return function() {
1396+ """ :: forall r. String -> Eff (trace :: Trace | r) Unit
1398+ -- | Write a value to the console, using its `Show` instance to produce a `String`.
1399+ print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
1400+ print o = trace (show o)
1402+module Control.Monad.ST where
1404+ import Control.Monad.Eff
1406+ -- | The `ST` effect represents _local mutation_, i.e. mutation which does not "escape" into the surrounding computation.
1408+ -- | An `ST` computation is parameterized by a phantom type which is used to restrict the set of reference cells it is allowed to access.
1410+ -- | The `runST` function can be used to handle the `ST` effect.
1411+ foreign import data ST :: * -> !
1413+ -- | The type `STRef s a` represents a mutable reference holding a value of type `a`, which can be used with the `ST s` effect.
1414+ foreign import data STRef :: * -> * -> *
1416+ -- | Create a new mutable reference.
1417+ foreign import newSTRef
1419+ function newSTRef(val) {
1420+ return function() {
1421+ return { value: val };
1424+ """ :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1426+ -- | Read the current value of a mutable reference.
1427+ foreign import readSTRef
1429+ function readSTRef(ref) {
1430+ return function() {
1434+ """ :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1436+ -- | Modify the value of a mutable reference by applying a function to the current value.
1437+ foreign import modifySTRef
1439+ function modifySTRef(ref) {
1440+ return function(f) {
1441+ return function() {
1442+ return ref.value = f(ref.value);
1446+ """ :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1448+ -- | Set the value of a mutable reference.
1449+ foreign import writeSTRef
1451+ function writeSTRef(ref) {
1452+ return function(a) {
1453+ return function() {
1454+ return ref.value = a;
1458+ """ :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1460+ -- | Run an `ST` computation.
1462+ -- | 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
1463+ -- | to the surrounding computation.
1465+ -- | It may cause problems to apply this function using the `$` operator. The recommended approach is to use parentheses instead.
1466+ foreign import runST
1468+ function runST(f) {
1471+ """ :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1473+ -- | A convenience function which combines `runST` with `runPure`, which can be used when the only required effect is `ST`.
1475+ -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1476+ -- | is to use parentheses instead.
1477+ pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
1478+ pureST st = runPure (runST st)