@@ -1,1572 +0,0 @@
7− , Semigroupoid, (<<<), (>>>)
12− , Functor, (<$>), (<#>), void
14− , Applicative, pure, liftA1
16− , Monad, return, liftM1, ap
17− , Semigroup, (<>), (++)
18− , Semiring, (+), zero, (*), one
19− , ModuloSemiring, (/), mod
25− , Ordering(..), Ord, compare, (<), (>), (<=), (>=)
26− , Bounded, top, bottom
27− , Lattice, sup, inf, (||), (&&)
29− , ComplementedLattice, not
30− , DistributiveLattice
32− , Bits, (.&.), (.|.), (.^.), shl, shr, zshr, complement
35− -- | The `Unit` type has a single inhabitant, called `unit`. It represents values with no computational content.
37− -- | `Unit` is often used, wrapped in a monadic type constructor, as the 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.
45− -- | An alias for `true`, which can be useful in guard clauses:
48− -- | max x y | x >= y = x
54− -- | Flips the order of the arguments to a function of two arguments.
57− -- | flip const 1 2 = const 2 1 = 2
59− flip :: forall a b c. (a -> b -> c) -> b -> a -> c
62− -- | Returns its first argument and ignores its second.
65− -- | const 1 "hello" = 1
67− const :: forall a b. a -> b -> a
70− -- | This function returns its first argument, and can be used to assert type equalities.
71− -- | This can be useful when types are otherwise ambiguous.
74− -- | main = print $ [] `asTypeOf` [0]
77− -- | If instead, we had written `main = print []`, the type of the argument `[]` would have
78− -- | been ambiguous, resulting in a compile-time error.
79− asTypeOf :: forall a. a -> a -> a
85− -- | A `Semigroupoid` is similar to a [`Category`](#category) but does not require an identity
86− -- | element `id`, just composable morphisms.
88− -- | `Semigroupoid`s should obey the following rule:
90− -- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
92− -- | One example of a `Semigroupoid` is the function type constructor `(->)`, with `(<<<)` defined
93− -- | as function composition.
94− class Semigroupoid a where
95− (<<<) :: forall b c d. a c d -> a b c -> a b d
97− instance semigroupoidArr :: Semigroupoid (->) where
98− (<<<) f g x = f (g x)
100− -- | Forwards composition, or `(<<<)` with its arguments reversed.
101− (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
104− -- | `Category`s consist of objects and composable morphisms between them, and as such are
105− -- | [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids` must have an identity element.
107− -- | `Category`s should obey the following rules.
109− -- | - Left Identity: `id <<< p = p`
110− -- | - Right Identity: `p <<< id = p`
111− class (Semigroupoid a) <= Category a where
112− id :: forall t. a t t
114− instance categoryArr :: Category (->) where
120− -- | Applies a function to its argument.
123− -- | length $ groupBy productCategory $ filter isInStock $ products
126− -- | is equivalent to
129− -- | length (groupBy productCategory (filter isInStock products))
132− -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of left, so
133− -- | `a $ b $ c $ d x` = `a $ (b $ (c $ (d $ x)))` = `a (b (c (d x)))`
134− ($) :: forall a b. (a -> b) -> a -> b
137− -- | Applies an argument to a function.
140− -- | products # filter isInStock # groupBy productCategory # length
143− -- | is equivalent to
146− -- | length (groupBy productCategory (filter isInStock products))
149− -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of right, so
150− -- | `x # a # b # c # d` = `(((x # a) # b) # c) # d` = `d (c (b (a x)))`
151− (#) :: forall a b. a -> (a -> b) -> b
156− -- | An infix alias for `cons`.
158− -- | Note, the running time of this function is `O(n)`.
159− (:) :: forall a. a -> [a] -> [a]
162− -- | Attaches an element to the front of an array, creating a new array.
165− -- | cons 1 [2, 3, 4] = [1, 2, 3, 4]
168− -- | Note, the running time of this function is `O(n)`.
172− return function(l) {
173− return [e].concat(l);
176− """ :: forall a. a -> [a] -> [a]
178− -- | The `Show` type class represents those types which can be converted into a human-readable `String` representation.
180− -- | While not required, it is recommended that for any expression `x`, the string `show x` be executable PureScript code
181− -- | which evaluates to the same value as the expression `x`.
185− instance showBoolean :: Show Boolean where
187− show false = "false"
189− instance showNumber :: Show Number where
190− show = showNumberImpl
192− instance showString :: Show String where
193− show = showStringImpl
195− instance showUnit :: Show Unit where
198− instance showArray :: (Show a) => Show [a] where
199− show = showArrayImpl show
201− instance showOrdering :: Show Ordering where
206− foreign import showNumberImpl
208− function showNumberImpl(n) {
209− return n.toString();
211− """ :: Number -> String
213− foreign import showStringImpl
215− function showStringImpl(s) {
216− return JSON.stringify(s);
218− """ :: String -> String
220− foreign import showArrayImpl
222− function showArrayImpl(f) {
223− return function(xs) {
225− for (var i = 0, l = xs.length; i < l; i++) {
228− return '[' + ss.join(',') + ']';
231− """ :: forall a. (a -> String) -> [a] -> String
236− -- | A `Functor` is a type constructor which supports a mapping operation `(<$>)`.
238− -- | `(<$>)` can be used to turn functions `a -> b` into functions `f a -> f b` whose argument and return
239− -- | types use the type constructor `f` to represent some computational context.
241− -- | `Functor` instances should satisfy the following laws:
243− -- | - Identity: `(<$>) id = id`
244− -- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
245− class Functor f where
246− (<$>) :: forall a b. (a -> b) -> f a -> f b
248− instance functorArr :: Functor ((->) r) where
251− -- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
254− -- | [1, 2, 3] <#> \n -> n * n
256− (<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
257− (<#>) fa f = f <$> fa
259− -- | The `void` function is used to ignore the type wrapped by a [`Functor`](#functor), replacing it with `Unit` and
260− -- | keeping only the type information provided by the type constructor itself.
262− -- | `void` is often useful when using `do` notation to change the return type of a monadic computation:
265− -- | main = forE 1 10 \n -> void do
269− void :: forall f a. (Functor f) => f a -> f Unit
270− void fa = const unit <$> fa
274− -- | The `Apply` class provides the `(<*>)` which is used to apply a function to an argument under a type constructor.
276− -- | `Apply` can be used to lift functions of two or more arguments to work on values wrapped with the type constructor `f`.
277− -- | It might also be understood in terms of the `lift2` function:
280− -- | lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
281− -- | lift2 f a b = f <$> a <*> b
284− -- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts the function application operator `($)` to arguments
285− -- | wrapped with the type constructor `f`.
287− -- | `Apply` instances should satisfy the following law:
289− -- | - Associative Composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
291− -- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
292− class (Functor f) <= Apply f where
293− (<*>) :: forall a b. f (a -> b) -> f a -> f b
295− instance applyArr :: Apply ((->) r) where
296− (<*>) f g x = f x (g x)
298− -- | The `Applicative` type class extends the [`Apply`](#apply) type class with a `pure` function, which can be used to
299− -- | create values of type `f a` from values of type `a`.
301− -- | Where [`Apply`](#apply) provides the ability to lift functions of two or more arguments to functions whose arguments are wrapped using `f`,
302− -- | and [`Functor`](#functor) provides the ability to lift functions of one argument, `pure` can be seen as the function which lifts functions of
303− -- | _zero_ arguments. That is, `Applicative` functors support a lifting operation for any number of function arguments.
305− -- | `Applicative` instances should satisfy the following laws:
307− -- | - Identity: `(pure id) <*> v = v`
308− -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
309− -- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
310− -- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
311− class (Apply f) <= Applicative f where
312− pure :: forall a. a -> f a
314− instance applicativeArr :: Applicative ((->) r) where
317− -- | `return` is an alias for `pure`.
318− return :: forall m a. (Applicative m) => a -> m a
321− -- | `liftA1` provides a default implementation of `(<$>)` for any [`Applicative`](#applicative) functor,
322− -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass relationship.
324− -- | `liftA1` can therefore be used to write [`Functor`](#functor) instances as follows:
327− -- | instance functorF :: Functor F where
330− liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
331− liftA1 f a = pure f <*> a
335− -- | The `Bind` type class extends the [`Apply`](#apply) type class with a "bind" operation `(>>=)` which composes computations
336− -- | in sequence, using the return value of one computation to determine the next computation.
338− -- | The `>>=` operator can also be expressed using `do` notation, as follows:
341− -- | x >>= f = do y <- x
345− -- | where the function argument of `f` is given the name `y`.
347− -- | `Bind` instances should satisfy the following law:
349− -- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
351− -- | Or, expressed using `do` notation:
353− -- | - Associativity: `do { z <- do { y <- x ; f y } ; g z } = do { k <- x ; do { y <- f k ; g y } }`
355− -- | Associativity tells us that we can regroup operations which use do-notation, so that we can unambiguously write, for example:
362− class (Apply m) <= Bind m where
363− (>>=) :: forall a b. m a -> (a -> m b) -> m b
365− instance bindArr :: Bind ((->) r) where
366− (>>=) m f x = f (m x) x
368− -- | The `Monad` type class combines the operations of the `Bind` and `Applicative` type classes. Therefore, `Monad` instances
369− -- | represent type constructors which support sequential composition, and also lifting of functions of arbitrary arity.
371− -- | `Monad` instances should satisfy the following laws:
373− -- | - Left Identity: `pure x >>= f = f x`
374− -- | - Right Identity: `x >>= pure = x`
376− -- | Or, expressed using `do` notation:
378− -- | - Left Identity: `do { y <- pure x ; f y } = f x`
379− -- | - Right Identity: `do { y <- x ; pure y } = x`
380− class (Applicative m, Bind m) <= Monad m
382− instance monadArr :: Monad ((->) r)
384− -- | `liftM1` provides a default implementation of `(<$>)` for any [`Monad`](#monad),
385− -- | without using `(<$>)` as provided by the [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
387− -- | `liftM1` can therefore be used to write [`Functor`](#functor) instances as follows:
390− -- | instance functorF :: Functor F where
393− liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
398− -- | `ap` provides a default implementation of `(<*>)` for any [`Monad`](#monad),
399− -- | without using `(<*>)` as provided by the [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
401− -- | `ap` can therefore be used to write [`Apply`](#apply) instances as follows:
404− -- | instance applyF :: Apply F where
407− ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
416− -- | The `Semigroup` type class identifies an associative operation on a type.
418− -- | `Semigroup` instances are required to satisfy the following law:
420− -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
422− -- | For example, the `String` type is an instance of `Semigroup`, where `(<>)` is defined to be string concatenation.
423− class Semigroup a where
426− -- | `(++)` is an alias for `(<>)`.
427− (++) :: forall s. (Semigroup s) => s -> s -> s
430− instance semigroupString :: Semigroup String where
433− instance semigroupUnit :: Semigroup Unit where
436− instance semigroupArr :: (Semigroup s') => Semigroup (s -> s') where
437− (<>) f g = \x -> f x <> g x
439− instance semigroupOrdering :: Semigroup Ordering where
444− foreign import concatString
446− function concatString(s1) {
447− return function(s2) {
451− """ :: String -> String -> String
456− -- | Addition and multiplication, satisfying the following laws:
458− -- | - `a` is a commutative monoid under addition
459− -- | - `a` is a monoid under multiplication
460− -- | - multiplication distributes over addition
461− -- | - multiplication by `zero` annihilates `a`
462− class Semiring a where
468− instance semiringNumber :: Semiring Number where
474− instance semiringUnit :: Semiring Unit where
482− -- | Addition, multiplication, modulo operation and division, satisfying:
484− -- | - ```a / b * b + (a `mod` b) = a```
485− class (Semiring a) <= ModuloSemiring a where
489− instance moduloSemiringNumber :: ModuloSemiring Number where
493− instance moduloSemiringUnit :: ModuloSemiring Unit where
499− -- | Addition, multiplication, and subtraction.
501− -- | Has the same laws as `Semiring` but additionally satisfying:
503− -- | - `a` is an abelian group under addition
504− class (Semiring a) <= Ring a where
507− instance ringNumber :: Ring Number where
510− instance ringUnit :: Ring Unit where
513− negate :: forall a. (Ring a) => a -> a
516− -- | Ring where every nonzero element has a multiplicative inverse so that:
518− -- | - ```a `mod` b = zero```
519− class (Ring a, ModuloSemiring a) <= DivisionRing a
521− instance divisionRingNumber :: DivisionRing Number
523− instance divisionRingUnit :: DivisionRing Unit
525− -- | A commutative field
526− class (DivisionRing a) <= Num a
528− instance numNumber :: Num Number
530− instance numUnit :: Num Unit
535− foreign import numAdd
537− function numAdd(n1) {
538− return function(n2) {
542− """ :: Number -> Number -> Number
544− foreign import numMul
546− function numMul(n1) {
547− return function(n2) {
551− """ :: Number -> Number -> Number
553− foreign import numDiv
555− function numDiv(n1) {
556− return function(n2) {
560− """ :: Number -> Number -> Number
562− foreign import numSub
564− function numSub(n1) {
565− return function(n2) {
569− """ :: Number -> Number -> Number
571− foreign import numMod
573− function numMod(n1) {
574− return function(n2) {
578− """ :: Number -> Number -> Number
583− -- | The `Eq` type class represents types which support decidable equality.
585− -- | `Eq` instances should satisfy the following laws:
587− -- | - Reflexivity: `x == x = true`
588− -- | - Symmetry: `x == y = y == x`
589− -- | - Transitivity: if `x == y` and `y == z` then `x == z`
590− -- | - Negation: `x /= y = not (x == y)`
592− -- | `(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
594− (==) :: a -> a -> Boolean
595− (/=) :: a -> a -> Boolean
597− instance eqBoolean :: Eq Boolean where
601− instance eqNumber :: Eq Number where
605− instance eqString :: Eq String where
609− instance eqUnit :: Eq Unit where
613− instance eqArray :: (Eq a) => Eq [a] where
614− (==) = eqArrayImpl (==)
615− (/=) xs ys = not (xs == ys)
617− foreign import refEq
619− function refEq(r1) {
620− return function(r2) {
624− """ :: forall a. a -> a -> Boolean
626− foreign import refIneq
628− function refIneq(r1) {
629− return function(r2) {
633− """ :: forall a. a -> a -> Boolean
635− foreign import eqArrayImpl
637− function eqArrayImpl(f) {
638− return function(xs) {
639− return function(ys) {
640− if (xs.length !== ys.length) return false;
641− for (var i = 0; i < xs.length; i++) {
642− if (!f(xs[i])(ys[i])) return false;
648− """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
650− -- | The `Ordering` data type represents the three possible outcomes of comparing two values:
652− -- | `LT` - The first value is _less than_ the second.
653− -- | `GT` - The first value is _greater than_ the second.
654− -- | `EQ` - The first value is _equal to_ or _incomparable to_ the second.
655− data Ordering = LT | GT | EQ
657− -- | The `Ord` type class represents types which support comparisons.
659− -- | `Ord` instances should satisfy the laws of _partially orderings_:
661− -- | - Reflexivity: `a <= a`
662− -- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
663− -- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
664− class (Eq a) <= Ord a where
665− compare :: a -> a -> Ordering
667− instance ordBoolean :: Ord Boolean where
668− compare false false = EQ
669− compare false true = LT
670− compare true true = EQ
671− compare true false = GT
673− instance ordNumber :: Ord Number where
674− compare = unsafeCompare
676− instance ordString :: Ord String where
677− compare = unsafeCompare
679− instance ordUnit :: Ord Unit where
682− instance ordArray :: (Ord a) => Ord [a] where
686− compare (x:xs) (y:ys) = case compare x y of
690− instance eqOrdering :: Eq Ordering where
695− (/=) x y = not (x == y)
702− -- | Test whether one value is _strictly less than_ another.
703− (<) :: forall a. (Ord a) => a -> a -> Boolean
704− (<) a1 a2 = case a1 `compare` a2 of
708− -- | Test whether one value is _strictly greater than_ another.
709− (>) :: forall a. (Ord a) => a -> a -> Boolean
710− (>) a1 a2 = case a1 `compare` a2 of
714− -- | Test whether one value is _non-strictly less than_ another.
715− (<=) :: forall a. (Ord a) => a -> a -> Boolean
716− (<=) a1 a2 = case a1 `compare` a2 of
720− -- | Test whether one value is _non-strictly greater than_ another.
721− (>=) :: forall a. (Ord a) => a -> a -> Boolean
722− (>=) a1 a2 = case a1 `compare` a2 of
726− unsafeCompare :: forall a. a -> a -> Ordering
727− unsafeCompare = unsafeCompareImpl LT EQ GT
729− foreign import unsafeCompareImpl
731− function unsafeCompareImpl(lt) {
732− return function(eq) {
733− return function(gt) {
734− return function(x) {
735− return function(y) {
736− return x < y ? lt : x > y ? gt : eq;
742− """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
744− -- | The `Bounded` type class represents types that are finite partially
747− -- | Instances should satisfy the following law in addition to the `Ord` laws:
749− -- | - Ordering: `bottom <= a <= top`
750− class (Ord a) <= Bounded a where
754− instance boundedBoolean :: Bounded Boolean where
758− instance boundedUnit :: Bounded Unit where
762− -- | The `Lattice` type class represents types that are partially ordered
763− -- | sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`).
765− -- | Instances should satisfy the following laws in addition to the `Ord`
768− -- | - Associativity:
769− -- | - `a || (b || c) = (a || b) || c`
770− -- | - `a && (b && c) = (a && b) && c`
771− -- | - Commutativity:
772− -- | - `a || b = b || a`
773− -- | - `a && b = b && a`
775− -- | - `a || (a && b) = a`
776− -- | - `a && (a || b) = a`
780− class (Ord a) <= Lattice a where
784− instance latticeBoolean :: Lattice Boolean where
791− -- | The `sup` operator.
792− (||) :: forall a. (Lattice a) => a -> a -> a
795− -- | The `inf` operator.
796− (&&) :: forall a. (Lattice a) => a -> a -> a
799− -- | The `BoundedLattice` type class represents types that are finite
802− -- | Instances should satisfy the following law in addition to the `Lattice`
803− -- | and `Bounded` laws:
806− -- | - `a || bottom = a`
807− -- | - `a && top = a`
808− -- | - Annihiliation:
809− -- | - `a || top = top`
810− -- | - `a && bottom = bottom`
811− class (Bounded a, Lattice a) <= BoundedLattice a
813− instance boundedLatticeBoolean :: BoundedLattice Boolean
815− -- | The `ComplementedLattice` type class represents types that are lattices
816− -- | where every member is also uniquely complemented.
818− -- | Instances should satisfy the following law in addition to the
819− -- | `BoundedLattice` laws:
821− -- | - Complemented:
822− -- | - `not a || a == top`
823− -- | - `not a && a == bottom`
824− -- | - Double negation:
825− -- | - `not <<< not == id`
826− class (BoundedLattice a) <= ComplementedLattice a where
829− instance complementedLatticeBoolean :: ComplementedLattice Boolean where
832− -- | The `DistributiveLattice` type class represents types that are lattices
833− -- | where the `&&` and `||` distribute over each other.
835− -- | Instances should satisfy the following law in addition to the `Lattice`
838− -- | - Distributivity: `x && (y || z) = (x && y) || (x && z)`
839− class (Lattice a) <= DistributiveLattice a
841− instance distributiveLatticeBoolean :: DistributiveLattice Boolean
843− -- | The `BooleanAlgebra` type class represents types that are Boolean
844− -- | algebras, also known as Boolean lattices.
846− -- | Instances should satisfy the `ComplementedLattice` and
847− -- | `DistributiveLattice` laws.
848− class (ComplementedLattice a, DistributiveLattice a) <= BooleanAlgebra a
850− instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
852− foreign import boolOr
854− function boolOr(b1) {
855− return function(b2) {
859− """ :: Boolean -> Boolean -> Boolean
861− foreign import boolAnd
863− function boolAnd(b1) {
864− return function(b2) {
868− """ :: Boolean -> Boolean -> Boolean
870− foreign import boolNot
872− function boolNot(b) {
875− """ :: Boolean -> Boolean
881− -- | The `Bits` type class identifies types which support bitwise operations.
883− (.&.) :: b -> b -> b
884− (.|.) :: b -> b -> b
885− (.^.) :: b -> b -> b
886− shl :: b -> Number -> b
887− shr :: b -> Number -> b
888− zshr :: b -> Number -> b
889− complement :: b -> b
891− instance bitsNumber :: Bits Number where
898− complement = numComplement
900− foreign import numAnd
902− function numAnd(n1) {
903− return function(n2) {
907− """ :: Number -> Number -> Number
909− foreign import numOr
911− function numOr(n1) {
912− return function(n2) {
916− """ :: Number -> Number -> Number
918− foreign import numXor
920− function numXor(n1) {
921− return function(n2) {
925− """ :: Number -> Number -> Number
927− foreign import numShl
929− function numShl(n1) {
930− return function(n2) {
934− """ :: Number -> Number -> Number
936− foreign import numShr
938− function numShr(n1) {
939− return function(n2) {
943− """ :: Number -> Number -> Number
945− foreign import numZshr
947− function numZshr(n1) {
948− return function(n2) {
952− """ :: Number -> Number -> Number
954− foreign import numComplement
956− function numComplement(n) {
959− """ :: Number -> Number
961−module Data.Function where
963− -- | The `on` function is used to change the domain of a binary operator.
965− -- | For example, we can create a function which compares two records based on the values of their `x` properties:
968− -- | compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
969− -- | compareX = compare `on` _.x
971− on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
972− on f g x y = g x `f` g y
974− -- | A function of zero arguments
975− foreign import data Fn0 :: * -> *
977− -- | A function of one argument
978− foreign import data Fn1 :: * -> * -> *
980− -- | A function of two arguments
981− foreign import data Fn2 :: * -> * -> * -> *
983− -- | A function of three arguments
984− foreign import data Fn3 :: * -> * -> * -> * -> *
986− -- | A function of four arguments
987− foreign import data Fn4 :: * -> * -> * -> * -> * -> *
989− -- | A function of five arguments
990− foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
992− -- | A function of six arguments
993− foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
995− -- | A function of seven arguments
996− foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
998− -- | A function of eight arguments
999− foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
1001− -- | A function of nine arguments
1002− foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
1004− -- | A function of ten arguments
1005− foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
1007− -- | Create a function of no arguments
1008− foreign import mkFn0
1010− function mkFn0(fn) {
1011− return function() {
1015− """ :: forall a. (Unit -> a) -> Fn0 a
1017− -- | Create a function of one argument
1018− foreign import mkFn1
1020− function mkFn1(fn) {
1021− return function(a) {
1025− """ :: forall a b. (a -> b) -> Fn1 a b
1027− -- | Create a function of two arguments from a curried function
1028− foreign import mkFn2
1030− function mkFn2(fn) {
1031− return function(a, b) {
1035− """ :: forall a b c. (a -> b -> c) -> Fn2 a b c
1037− -- | Create a function of three arguments from a curried function
1038− foreign import mkFn3
1040− function mkFn3(fn) {
1041− return function(a, b, c) {
1042− return fn(a)(b)(c);
1045− """ :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
1047− -- | Create a function of four arguments from a curried function
1048− foreign import mkFn4
1050− function mkFn4(fn) {
1051− return function(a, b, c, d) {
1052− return fn(a)(b)(c)(d);
1055− """ :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
1057− -- | Create a function of five arguments from a curried function
1058− foreign import mkFn5
1060− function mkFn5(fn) {
1061− return function(a, b, c, d, e) {
1062− return fn(a)(b)(c)(d)(e);
1065− """ :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
1067− -- | Create a function of six arguments from a curried function
1068− foreign import mkFn6
1070− function mkFn6(fn) {
1071− return function(a, b, c, d, e, f) {
1072− return fn(a)(b)(c)(d)(e)(f);
1075− """ :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
1077− -- | Create a function of seven arguments from a curried function
1078− foreign import mkFn7
1080− function mkFn7(fn) {
1081− return function(a, b, c, d, e, f, g) {
1082− return fn(a)(b)(c)(d)(e)(f)(g);
1085− """ :: 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
1087− -- | Create a function of eight arguments from a curried function
1088− foreign import mkFn8
1090− function mkFn8(fn) {
1091− return function(a, b, c, d, e, f, g, h) {
1092− return fn(a)(b)(c)(d)(e)(f)(g)(h);
1095− """ :: 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
1097− -- | Create a function of nine arguments from a curried function
1098− foreign import mkFn9
1100− function mkFn9(fn) {
1101− return function(a, b, c, d, e, f, g, h, i) {
1102− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i);
1105− """ :: 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
1107− -- | Create a function of ten arguments from a curried function
1108− foreign import mkFn10
1110− function mkFn10(fn) {
1111− return function(a, b, c, d, e, f, g, h, i, j) {
1112− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);
1115− """ :: 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
1117− -- | Apply a function of no arguments
1118− foreign import runFn0
1120− function runFn0(fn) {
1123− """ :: forall a. Fn0 a -> a
1125− -- | Apply a function of one argument
1126− foreign import runFn1
1128− function runFn1(fn) {
1129− return function(a) {
1133− """ :: forall a b. Fn1 a b -> a -> b
1135− -- | Apply a function of two arguments
1136− foreign import runFn2
1138− function runFn2(fn) {
1139− return function(a) {
1140− return function(b) {
1145− """ :: forall a b c. Fn2 a b c -> a -> b -> c
1147− -- | Apply a function of three arguments
1148− foreign import runFn3
1150− function runFn3(fn) {
1151− return function(a) {
1152− return function(b) {
1153− return function(c) {
1154− return fn(a, b, c);
1159− """ :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
1161− -- | Apply a function of four arguments
1162− foreign import runFn4
1164− function runFn4(fn) {
1165− return function(a) {
1166− return function(b) {
1167− return function(c) {
1168− return function(d) {
1169− return fn(a, b, c, d);
1175− """ :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
1177− -- | Apply a function of five arguments
1178− foreign import runFn5
1180− function runFn5(fn) {
1181− return function(a) {
1182− return function(b) {
1183− return function(c) {
1184− return function(d) {
1185− return function(e) {
1186− return fn(a, b, c, d, e);
1193− """ :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
1195− -- | Apply a function of six arguments
1196− foreign import runFn6
1198− function runFn6(fn) {
1199− return function(a) {
1200− return function(b) {
1201− return function(c) {
1202− return function(d) {
1203− return function(e) {
1204− return function(f) {
1205− return fn(a, b, c, d, e, f);
1213− """ :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
1215− -- | Apply a function of seven arguments
1216− foreign import runFn7
1218− function runFn7(fn) {
1219− return function(a) {
1220− return function(b) {
1221− return function(c) {
1222− return function(d) {
1223− return function(e) {
1224− return function(f) {
1225− return function(g) {
1226− return fn(a, b, c, d, e, f, g);
1235− """ :: 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
1237− -- | Apply a function of eight arguments
1238− foreign import runFn8
1240− function runFn8(fn) {
1241− return function(a) {
1242− return function(b) {
1243− return function(c) {
1244− return function(d) {
1245− return function(e) {
1246− return function(f) {
1247− return function(g) {
1248− return function(h) {
1249− return fn(a, b, c, d, e, f, g, h);
1259− """ :: 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
1261− -- | Apply a function of nine arguments
1262− foreign import runFn9
1264− function runFn9(fn) {
1265− return function(a) {
1266− return function(b) {
1267− return function(c) {
1268− return function(d) {
1269− return function(e) {
1270− return function(f) {
1271− return function(g) {
1272− return function(h) {
1273− return function(i) {
1274− return fn(a, b, c, d, e, f, g, h, i);
1285− """ :: 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
1287− -- | Apply a function of ten arguments
1288− foreign import runFn10
1290− function runFn10(fn) {
1291− return function(a) {
1292− return function(b) {
1293− return function(c) {
1294− return function(d) {
1295− return function(e) {
1296− return function(f) {
1297− return function(g) {
1298− return function(h) {
1299− return function(i) {
1300− return function(j) {
1301− return fn(a, b, c, d, e, f, g, h, i, j);
1313− """ :: 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
1315−module Prelude.Unsafe where
1317− -- | Find the element of an array at the specified index.
1319− -- | Note: this function can cause unpredictable failure at runtime if the index is out-of-bounds.
1320− foreign import unsafeIndex
1322− function unsafeIndex(xs) {
1323− return function(n) {
1327− """ :: forall a. [a] -> Number -> a
1329−module Control.Monad.Eff
1333− , untilE, whileE, forE, foreachE
1336− -- | The `Eff` type constructor is used to represent _native_ effects.
1338− -- | See [Handling Native Effects with the Eff Monad](https://github.com/purescript/purescript/wiki/Handling-Native-Effects-with-the-Eff-Monad) for more details.
1340− -- | 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.
1341− foreign import data Eff :: # ! -> * -> *
1343− foreign import returnE
1345− function returnE(a) {
1346− return function() {
1350− """ :: forall e a. a -> Eff e a
1352− foreign import bindE
1354− function bindE(a) {
1355− return function(f) {
1356− return function() {
1361− """ :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
1363− -- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled.
1365− -- | The `runPure` function can be used to run pure computations and obtain their result.
1366− type Pure a = forall e. Eff e a
1368− -- | Run a pure computation and return its result.
1370− -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1371− -- | is to use parentheses instead.
1372− foreign import runPure
1374− function runPure(f) {
1377− """ :: forall a. Pure a -> a
1379− instance functorEff :: Functor (Eff e) where
1382− instance applyEff :: Apply (Eff e) where
1385− instance applicativeEff :: Applicative (Eff e) where
1388− instance bindEff :: Bind (Eff e) where
1391− instance monadEff :: Monad (Eff e)
1393− -- | Loop until a condition becomes `true`.
1395− -- | `untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
1396− -- | until its return value is `true`.
1397− foreign import untilE
1399− function untilE(f) {
1400− return function() {
1405− """ :: forall e. Eff e Boolean -> Eff e Unit
1407− -- | Loop while a condition is `true`.
1409− -- | `whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
1410− -- | `true`, it runs the effectful computation `m` and loops. If not, the computation ends.
1411− foreign import whileE
1413− function whileE(f) {
1414− return function(a) {
1415− return function() {
1423− """ :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
1425− -- | Loop over a consecutive collection of numbers.
1427− -- | `forE lo hi f` runs the computation returned by the function `f` for each of the inputs
1428− -- | between `lo` (inclusive) and `hi` (exclusive).
1429− foreign import forE
1431− function forE(lo) {
1432− return function(hi) {
1433− return function(f) {
1434− return function() {
1435− for (var i = lo; i < hi; i++) {
1442− """ :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
1444− -- | Loop over an array of values.
1446− -- | `foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`.
1447− foreign import foreachE
1449− function foreachE(as) {
1450− return function(f) {
1451− return function() {
1452− for (var i = 0; i < as.length; i++) {
1458− """ :: forall e a. [a] -> (a -> Eff e Unit) -> Eff e Unit
1460−module Control.Monad.Eff.Unsafe where
1462− import Control.Monad.Eff
1464− -- | Change the type of an effectful computation, allowing it to be run in another context.
1466− -- | Note: use of this function can result in arbitrary side-effects.
1467− foreign import unsafeInterleaveEff
1469− function unsafeInterleaveEff(f) {
1472− """ :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
1474−module Debug.Trace where
1476− import Control.Monad.Eff
1478− -- | The `Trace` effect represents those computations which write to the console.
1479− foreign import data Trace :: !
1481− -- | Write a `String` to the console.
1482− foreign import trace
1484− function trace(s) {
1485− return function() {
1490− """ :: forall r. String -> Eff (trace :: Trace | r) Unit
1492− -- | Write a value to the console, using its `Show` instance to produce a `String`.
1493− print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
1494− print o = trace (show o)
1496−module Control.Monad.ST where
1498− import Control.Monad.Eff
1500− -- | The `ST` effect represents _local mutation_, i.e. mutation which does not "escape" into the surrounding computation.
1502− -- | An `ST` computation is parameterized by a phantom type which is used to restrict the set of reference cells it is allowed to access.
1504− -- | The `runST` function can be used to handle the `ST` effect.
1505− foreign import data ST :: * -> !
1507− -- | The type `STRef s a` represents a mutable reference holding a value of type `a`, which can be used with the `ST s` effect.
1508− foreign import data STRef :: * -> * -> *
1510− -- | Create a new mutable reference.
1511− foreign import newSTRef
1513− function newSTRef(val) {
1514− return function() {
1515− return { value: val };
1518− """ :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1520− -- | Read the current value of a mutable reference.
1521− foreign import readSTRef
1523− function readSTRef(ref) {
1524− return function() {
1528− """ :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1530− -- | Modify the value of a mutable reference by applying a function to the current value.
1531− foreign import modifySTRef
1533− function modifySTRef(ref) {
1534− return function(f) {
1535− return function() {
1536− return ref.value = f(ref.value);
1540− """ :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1542− -- | Set the value of a mutable reference.
1543− foreign import writeSTRef
1545− function writeSTRef(ref) {
1546− return function(a) {
1547− return function() {
1548− return ref.value = a;
1552− """ :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1554− -- | Run an `ST` computation.
1556− -- | 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
1557− -- | to the surrounding computation.
1559− -- | It may cause problems to apply this function using the `$` operator. The recommended approach is to use parentheses instead.
1560− foreign import runST
1562− function runST(f) {
1565− """ :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1567− -- | A convenience function which combines `runST` with `runPure`, which can be used when the only required effect is `ST`.
1569− -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1570− -- | is to use parentheses instead.
1571− pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
1572− pureST st = runPure (runST st)