git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove Prelude #1040
commit7296802ace5ba2838c65442616bba54b3b6b76de authorPhil Freeman <paf31@cantab.net> dateSun 12 Apr 2015, 16:38 (12 years ago) parent7e06121
10 files changed+10−3214
prelude/README.md−1636 prelude/images/Prelude.png prelude/prelude.purs−1551 prelude/updateDocs.sh−11 psc-make/Main.hs+2−4 psc/Main.hs+2−3 psci/PSCi.hs+1−1 purescript.cabal−1 src/Language/PureScript.hs−6 tests/Main.hs+5−1
prelude/README.mddeleted−1636
@@ -1,1636 +0,0 @@
1−# Module Documentation
2−
3−## Module Prelude
4−
5−#### `Unit`
6−
7−``` purescript
8−newtype Unit
9− = Unit { }
10−```
11−
12−The `Unit` type has a single inhabitant, called `unit`. It represents
13−values with no computational content.
14−
15−`Unit` is often used, wrapped in a monadic type constructor, as the
16−return type of a computation where only
17−the _effects_ are important.
18−
19−#### `unit`
20−
21−``` purescript
22−unit :: Unit
23−```
24−
25−`unit` is the sole inhabitant of the `Unit` type.
26−
27−#### `($)`
28−
29−``` purescript
30−($) :: forall a b. (a -> b) -> a -> b
31−```
32−
33−Applies a function to its argument.
34−
35−```purescript
36−length $ groupBy productCategory $ filter isInStock $ products
37−```
38−
39−is equivalent to:
40−
41−```purescript
42−length (groupBy productCategory (filter isInStock products))
43−```
44−
45−`($)` is different from [`(#)`](#-2) because it is right-infix instead of
46−left: `a $ b $ c $ d x = a $ (b $ (c $ (d $ x))) = a (b (c (d x)))`
47−
48−#### `(#)`
49−
50−``` purescript
51−(#) :: forall a b. a -> (a -> b) -> b
52−```
53−
54−Applies an argument to a function.
55−
56−```purescript
57−products # filter isInStock # groupBy productCategory # length
58−```
59−
60−is equivalent to:
61−
62−```purescript
63−length (groupBy productCategory (filter isInStock products))
64−```
65−
66−`(#)` is different from [`($)`](#-1) because it is left-infix instead of
67−right: `x # a # b # c # d = (((x # a) # b) # c) # d = d (c (b (a x)))`
68−
69−#### `flip`
70−
71−``` purescript
72−flip :: forall a b c. (a -> b -> c) -> b -> a -> c
73−```
74−
75−Flips the order of the arguments to a function of two arguments.
76−
77−```purescript
78−flip const 1 2 = const 2 1 = 2
79−```
80−
81−#### `const`
82−
83−``` purescript
84−const :: forall a b. a -> b -> a
85−```
86−
87−Returns its first argument and ignores its second.
88−
89−```purescript
90−const 1 "hello" = 1
91−```
92−
93−#### `asTypeOf`
94−
95−``` purescript
96−asTypeOf :: forall a. a -> a -> a
97−```
98−
99−This function returns its first argument, and can be used to assert type
100−equalities. This can be useful when types are otherwise ambiguous.
101−
102−```purescript
103−main = print $ [] `asTypeOf` [0]
104−```
105−
106−If instead, we had written `main = print []`, the type of the argument
107−`[]` would have been ambiguous, resulting in a compile-time error.
108−
109−#### `otherwise`
110−
111−``` purescript
112−otherwise :: Boolean
113−```
114−
115−An alias for `true`, which can be useful in guard clauses:
116−
117−```purescript
118−max x y | x >= y = x
119− | otherwise = y
120−```
121−
122−#### `cons`
123−
124−``` purescript
125−cons :: forall a. a -> [a] -> [a]
126−```
127−
128−Attaches an element to the front of an array, creating a new array.
129−
130−```purescript
131−cons 1 [2, 3, 4] = [1, 2, 3, 4]
132−```
133−
134−Note, the running time of this function is `O(n)`.
135−
136−#### `(:)`
137−
138−``` purescript
139−(:) :: forall a. a -> [a] -> [a]
140−```
141−
142−An infix alias for `cons`.
143−
144−Note, the running time of this function is `O(n)`.
145−
146−#### `Semigroupoid`
147−
148−``` purescript
149−class Semigroupoid a where
150− (<<<) :: forall b c d. a c d -> a b c -> a b d
151−```
152−
153−A `Semigroupoid` is similar to a [`Category`](#category) but does not
154−require an identity element `id`, just composable morphisms.
155−
156−`Semigroupoid`s must satisfy the following law:
157−
158−- Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
159−
160−One example of a `Semigroupoid` is the function type constructor `(->)`,
161−with `(<<<)` defined as function composition.
162−
163−#### `semigroupoidArr`
164−
165−``` purescript
166−instance semigroupoidArr :: Semigroupoid Prim.Function
167−```
168−
169−
170−#### `(>>>)`
171−
172−``` purescript
173−(>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
174−```
175−
176−Forwards composition, or `(<<<)` with its arguments reversed.
177−
178−#### `Category`
179−
180−``` purescript
181−class (Semigroupoid a) <= Category a where
182− id :: forall t. a t t
183−```
184−
185−`Category`s consist of objects and composable morphisms between them, and
186−as such are [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids`
187−must have an identity element.
188−
189−Instances must satisfy the following law in addition to the
190−`Semigroupoid` law:
191−
192−- Identity: `id <<< p = p <<< id = p`
193−
194−#### `categoryArr`
195−
196−``` purescript
197−instance categoryArr :: Category Prim.Function
198−```
199−
200−
201−#### `Functor`
202−
203−``` purescript
204−class Functor f where
205− (<$>) :: forall a b. (a -> b) -> f a -> f b
206−```
207−
208−A `Functor` is a type constructor which supports a mapping operation
209−`(<$>)`.
210−
211−`(<$>)` can be used to turn functions `a -> b` into functions
212−`f a -> f b` whose argument and return types use the type constructor `f`
213−to represent some computational context.
214−
215−Instances must satisfy the following laws:
216−
217−- Identity: `(<$>) id = id`
218−- Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
219−
220−#### `functorArr`
221−
222−``` purescript
223−instance functorArr :: Functor (Prim.Function r)
224−```
225−
226−
227−#### `(<#>)`
228−
229−``` purescript
230−(<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
231−```
232−
233−`(<#>)` is `(<$>)` with its arguments reversed. For example:
234−
235−```purescript
236−[1, 2, 3] <#> \n -> n * n
237−```
238−
239−#### `void`
240−
241−``` purescript
242−void :: forall f a. (Functor f) => f a -> f Unit
243−```
244−
245−The `void` function is used to ignore the type wrapped by a
246−[`Functor`](#functor), replacing it with `Unit` and keeping only the type
247−information provided by the type constructor itself.
248−
249−`void` is often useful when using `do` notation to change the return type
250−of a monadic computation:
251−
252−```purescript
253−main = forE 1 10 \n -> void do
254− print n
255− print (n * n)
256−```
257−
258−#### `Apply`
259−
260−``` purescript
261−class (Functor f) <= Apply f where
262− (<*>) :: forall a b. f (a -> b) -> f a -> f b
263−```
264−
265−The `Apply` class provides the `(<*>)` which is used to apply a function
266−to an argument under a type constructor.
267−
268−`Apply` can be used to lift functions of two or more arguments to work on
269−values wrapped with the type constructor `f`. It might also be understood
270−in terms of the `lift2` function:
271−
272−```purescript
273−lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
274−lift2 f a b = f <$> a <*> b
275−```
276−
277−`(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts
278−the function application operator `($)` to arguments wrapped with the
279−type constructor `f`.
280−
281−Instances must satisfy the following law in addition to the `Functor`
282−laws:
283−
284−- Associative composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
285−
286−Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
287−
288−#### `applyArr`
289−
290−``` purescript
291−instance applyArr :: Apply (Prim.Function r)
292−```
293−
294−
295−#### `Applicative`
296−
297−``` purescript
298−class (Apply f) <= Applicative f where
299− pure :: forall a. a -> f a
300−```
301−
302−The `Applicative` type class extends the [`Apply`](#apply) type class
303−with a `pure` function, which can be used to create values of type `f a`
304−from values of type `a`.
305−
306−Where [`Apply`](#apply) provides the ability to lift functions of two or
307−more arguments to functions whose arguments are wrapped using `f`, and
308−[`Functor`](#functor) provides the ability to lift functions of one
309−argument, `pure` can be seen as the function which lifts functions of
310−_zero_ arguments. That is, `Applicative` functors support a lifting
311−operation for any number of function arguments.
312−
313−Instances must satisfy the following laws in addition to the `Apply`
314−laws:
315−
316−- Identity: `(pure id) <*> v = v`
317−- Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
318−- Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
319−- Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
320−
321−#### `applicativeArr`
322−
323−``` purescript
324−instance applicativeArr :: Applicative (Prim.Function r)
325−```
326−
327−
328−#### `return`
329−
330−``` purescript
331−return :: forall m a. (Applicative m) => a -> m a
332−```
333−
334−`return` is an alias for `pure`.
335−
336−#### `liftA1`
337−
338−``` purescript
339−liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
340−```
341−
342−`liftA1` provides a default implementation of `(<$>)` for any
343−[`Applicative`](#applicative) functor, without using `(<$>)` as provided
344−by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass
345−relationship.
346−
347−`liftA1` can therefore be used to write [`Functor`](#functor) instances
348−as follows:
349−
350−```purescript
351−instance functorF :: Functor F where
352− (<$>) = liftA1
353−```
354−
355−#### `Bind`
356−
357−``` purescript
358−class (Apply m) <= Bind m where
359− (>>=) :: forall a b. m a -> (a -> m b) -> m b
360−```
361−
362−The `Bind` type class extends the [`Apply`](#apply) type class with a
363−"bind" operation `(>>=)` which composes computations in sequence, using
364−the return value of one computation to determine the next computation.
365−
366−The `>>=` operator can also be expressed using `do` notation, as follows:
367−
368−```purescript
369−x >>= f = do y <- x
370− f y
371−```
372−
373−where the function argument of `f` is given the name `y`.
374−
375−Instances must satisfy the following law in addition to the `Apply`
376−laws:
377−
378−- Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
379−
380−Associativity tells us that we can regroup operations which use `do`
381−notation so that we can unambiguously write, for example:
382−
383−```purescript
384−do x <- m1
385− y <- m2 x
386− m3 x y
387−```
388−
389−#### `bindArr`
390−
391−``` purescript
392−instance bindArr :: Bind (Prim.Function r)
393−```
394−
395−
396−#### `Monad`
397−
398−``` purescript
399−class (Applicative m, Bind m) <= Monad m where
400−```
401−
402−The `Monad` type class combines the operations of the `Bind` and
403−`Applicative` type classes. Therefore, `Monad` instances represent type
404−constructors which support sequential composition, and also lifting of
405−functions of arbitrary arity.
406−
407−Instances must satisfy the following laws in addition to the
408−`Applicative` and `Bind` laws:
409−
410−- Left Identity: `pure x >>= f = f x`
411−- Right Identity: `x >>= pure = x`
412−
413−#### `monadArr`
414−
415−``` purescript
416−instance monadArr :: Monad (Prim.Function r)
417−```
418−
419−
420−#### `liftM1`
421−
422−``` purescript
423−liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
424−```
425−
426−`liftM1` provides a default implementation of `(<$>)` for any
427−[`Monad`](#monad), without using `(<$>)` as provided by the
428−[`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
429−
430−`liftM1` can therefore be used to write [`Functor`](#functor) instances
431−as follows:
432−
433−```purescript
434−instance functorF :: Functor F where
435− (<$>) = liftM1
436−```
437−
438−#### `ap`
439−
440−``` purescript
441−ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
442−```
443−
444−`ap` provides a default implementation of `(<*>)` for any
445−[`Monad`](#monad), without using `(<*>)` as provided by the
446−[`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
447−
448−`ap` can therefore be used to write [`Apply`](#apply) instances as
449−follows:
450−
451−```purescript
452−instance applyF :: Apply F where
453− (<*>) = ap
454−```
455−
456−#### `Semigroup`
457−
458−``` purescript
459−class Semigroup a where
460− (<>) :: a -> a -> a
461−```
462−
463−The `Semigroup` type class identifies an associative operation on a type.
464−
465−Instances are required to satisfy the following law:
466−
467−- Associativity: `(x <> y) <> z = x <> (y <> z)`
468−
469−One example of a `Semigroup` is `String`, with `(<>)` defined as string
470−concatenation.
471−
472−#### `(++)`
473−
474−``` purescript
475−(++) :: forall s. (Semigroup s) => s -> s -> s
476−```
477−
478−`(++)` is an alias for `(<>)`.
479−
480−#### `semigroupString`
481−
482−``` purescript
483−instance semigroupString :: Semigroup String
484−```
485−
486−
487−#### `semigroupUnit`
488−
489−``` purescript
490−instance semigroupUnit :: Semigroup Unit
491−```
492−
493−
494−#### `semigroupArr`
495−
496−``` purescript
497−instance semigroupArr :: (Semigroup s') => Semigroup (s -> s')
498−```
499−
500−
501−#### `semigroupOrdering`
502−
503−``` purescript
504−instance semigroupOrdering :: Semigroup Ordering
505−```
506−
507−
508−#### `Semiring`
509−
510−``` purescript
511−class Semiring a where
512− (+) :: a -> a -> a
513− zero :: a
514− (*) :: a -> a -> a
515− one :: a
516−```
517−
518−The `Semiring` class is for types that support an addition and
519−multiplication operation.
520−
521−Instances must satisfy the following laws:
522−
523−- Commutative monoid under addition:
524− - Associativity: `(a + b) + c = a + (b + c)`
525− - Identity: `zero + a = a + zero = a`
526− - Commutative: `a + b = b + a`
527−- Monoid under multiplication:
528− - Associativity: `(a * b) * c = a * (b * c)`
529− - Identity: `one * a = a * one = a`
530−- Multiplication distributes over addition:
531− - Left distributivity: `a * (b + c) = (a * b) + (a * c)`
532− - Right distributivity: `(a + b) * c = (a * c) + (b * c)`
533−- Annihiliation: `zero * a = a * zero = zero`
534−
535−#### `semiringNumber`
536−
537−``` purescript
538−instance semiringNumber :: Semiring Number
539−```
540−
541−
542−#### `semiringUnit`
543−
544−``` purescript
545−instance semiringUnit :: Semiring Unit
546−```
547−
548−
549−#### `Ring`
550−
551−``` purescript
552−class (Semiring a) <= Ring a where
553− (-) :: a -> a -> a
554−```
555−
556−The `Ring` class is for types that support addition, multiplication,
557−and subtraction operations.
558−
559−Instances must satisfy the following law in addition to the `Semiring`
560−laws:
561−
562−- Additive inverse: `a + (-a) = (-a) + a = zero`
563−
564−#### `ringNumber`
565−
566−``` purescript
567−instance ringNumber :: Ring Number
568−```
569−
570−
571−#### `ringUnit`
572−
573−``` purescript
574−instance ringUnit :: Ring Unit
575−```
576−
577−
578−#### `negate`
579−
580−``` purescript
581−negate :: forall a. (Ring a) => a -> a
582−```
583−
584−
585−#### `ModuloSemiring`
586−
587−``` purescript
588−class (Semiring a) <= ModuloSemiring a where
589− (/) :: a -> a -> a
590− mod :: a -> a -> a
591−```
592−
593−The `ModuloSemiring` class is for types that support addition,
594−multiplication, division, and modulo (division remainder) operations.
595−
596−Instances must satisfy the following law in addition to the `Semiring`
597−laws:
598−
599−- Remainder: `a / b * b + (a `mod` b) = a`
600−
601−#### `moduloSemiringNumber`
602−
603−``` purescript
604−instance moduloSemiringNumber :: ModuloSemiring Number
605−```
606−
607−
608−#### `moduloSemiringUnit`
609−
610−``` purescript
611−instance moduloSemiringUnit :: ModuloSemiring Unit
612−```
613−
614−
615−#### `DivisionRing`
616−
617−``` purescript
618−class (Ring a, ModuloSemiring a) <= DivisionRing a where
619−```
620−
621−A `Ring` where every nonzero element has a multiplicative inverse.
622−
623−Instances must satisfy the following law in addition to the `Ring` and
624−`ModuloSemiring` laws:
625−
626−- Multiplicative inverse: `(one / x) * x = one`
627−
628−As a consequence of this ```a `mod` b = zero``` as no divide operation
629−will have a remainder.
630−
631−#### `divisionRingNumber`
632−
633−``` purescript
634−instance divisionRingNumber :: DivisionRing Number
635−```
636−
637−
638−#### `divisionRingUnit`
639−
640−``` purescript
641−instance divisionRingUnit :: DivisionRing Unit
642−```
643−
644−
645−#### `Num`
646−
647−``` purescript
648−class (DivisionRing a) <= Num a where
649−```
650−
651−The `Num` class is for types that are commutative fields.
652−
653−Instances must satisfy the following law in addition to the
654−`DivisionRing` laws:
655−
656−- Commutative multiplication: `a * b = b * a`
657−
658−#### `numNumber`
659−
660−``` purescript
661−instance numNumber :: Num Number
662−```
663−
664−
665−#### `numUnit`
666−
667−``` purescript
668−instance numUnit :: Num Unit
669−```
670−
671−
672−#### `Eq`
673−
674−``` purescript
675−class Eq a where
676− (==) :: a -> a -> Boolean
677− (/=) :: a -> a -> Boolean
678−```
679−
680−The `Eq` type class represents types which support decidable equality.
681−
682−`Eq` instances should satisfy the following laws:
683−
684−- Reflexivity: `x == x = true`
685−- Symmetry: `x == y = y == x`
686−- Transitivity: if `x == y` and `y == z` then `x == z`
687−- Negation: `x /= y = not (x == y)`
688−
689−`(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
690−
691−#### `eqBoolean`
692−
693−``` purescript
694−instance eqBoolean :: Eq Boolean
695−```
696−
697−
698−#### `eqNumber`
699−
700−``` purescript
701−instance eqNumber :: Eq Number
702−```
703−
704−
705−#### `eqString`
706−
707−``` purescript
708−instance eqString :: Eq String
709−```
710−
711−
712−#### `eqUnit`
713−
714−``` purescript
715−instance eqUnit :: Eq Unit
716−```
717−
718−
719−#### `eqArray`
720−
721−``` purescript
722−instance eqArray :: (Eq a) => Eq [a]
723−```
724−
725−
726−#### `eqOrdering`
727−
728−``` purescript
729−instance eqOrdering :: Eq Ordering
730−```
731−
732−
733−#### `Ordering`
734−
735−``` purescript
736−data Ordering
737− = LT
738− | GT
739− | EQ
740−```
741−
742−The `Ordering` data type represents the three possible outcomes of
743−comparing two values:
744−
745−`LT` - The first value is _less than_ the second.
746−`GT` - The first value is _greater than_ the second.
747−`EQ` - The first value is _equal to_ or _incomparable to_ the second.
748−
749−#### `Ord`
750−
751−``` purescript
752−class (Eq a) <= Ord a where
753− compare :: a -> a -> Ordering
754−```
755−
756−The `Ord` type class represents types which support comparisons.
757−
758−`Ord` instances should satisfy the laws of _partially orderings_:
759−
760−- Reflexivity: `a <= a`
761−- Antisymmetry: if `a <= b` and `b <= a` then `a = b`
762−- Transitivity: if `a <= b` and `b <= c` then `a <= c`
763−
764−#### `ordBoolean`
765−
766−``` purescript
767−instance ordBoolean :: Ord Boolean
768−```
769−
770−
771−#### `ordNumber`
772−
773−``` purescript
774−instance ordNumber :: Ord Number
775−```
776−
777−
778−#### `ordString`
779−
780−``` purescript
781−instance ordString :: Ord String
782−```
783−
784−
785−#### `ordUnit`
786−
787−``` purescript
788−instance ordUnit :: Ord Unit
789−```
790−
791−
792−#### `ordArray`
793−
794−``` purescript
795−instance ordArray :: (Ord a) => Ord [a]
796−```
797−
798−
799−#### `ordOrdering`
800−
801−``` purescript
802−instance ordOrdering :: Ord Ordering
803−```
804−
805−
806−#### `(<)`
807−
808−``` purescript
809−(<) :: forall a. (Ord a) => a -> a -> Boolean
810−```
811−
812−Test whether one value is _strictly less than_ another.
813−
814−#### `(>)`
815−
816−``` purescript
817−(>) :: forall a. (Ord a) => a -> a -> Boolean
818−```
819−
820−Test whether one value is _strictly greater than_ another.
821−
822−#### `(<=)`
823−
824−``` purescript
825−(<=) :: forall a. (Ord a) => a -> a -> Boolean
826−```
827−
828−Test whether one value is _non-strictly less than_ another.
829−
830−#### `(>=)`
831−
832−``` purescript
833−(>=) :: forall a. (Ord a) => a -> a -> Boolean
834−```
835−
836−Test whether one value is _non-strictly greater than_ another.
837−
838−#### `Bounded`
839−
840−``` purescript
841−class (Ord a) <= Bounded a where
842− top :: a
843− bottom :: a
844−```
845−
846−The `Bounded` type class represents types that are finite partially
847−ordered sets.
848−
849−Instances should satisfy the following law in addition to the `Ord` laws:
850−
851−- Ordering: `bottom <= a <= top`
852−
853−#### `boundedBoolean`
854−
855−``` purescript
856−instance boundedBoolean :: Bounded Boolean
857−```
858−
859−
860−#### `boundedUnit`
861−
862−``` purescript
863−instance boundedUnit :: Bounded Unit
864−```
865−
866−
867−#### `boundedOrdering`
868−
869−``` purescript
870−instance boundedOrdering :: Bounded Ordering
871−```
872−
873−
874−#### `Lattice`
875−
876−``` purescript
877−class (Ord a) <= Lattice a where
878− sup :: a -> a -> a
879− inf :: a -> a -> a
880−```
881−
882−The `Lattice` type class represents types that are partially ordered
883−sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`).
884−
885−Instances should satisfy the following laws in addition to the `Ord`
886−laws:
887−
888−- Associativity:
889− - `a || (b || c) = (a || b) || c`
890− - `a && (b && c) = (a && b) && c`
891−- Commutativity:
892− - `a || b = b || a`
893− - `a && b = b && a`
894−- Absorption:
895− - `a || (a && b) = a`
896− - `a && (a || b) = a`
897−- Idempotent:
898− - `a || a = a`
899− - `a && a = a`
900−
901−#### `latticeBoolean`
902−
903−``` purescript
904−instance latticeBoolean :: Lattice Boolean
905−```
906−
907−
908−#### `latticeUnit`
909−
910−``` purescript
911−instance latticeUnit :: Lattice Unit
912−```
913−
914−
915−#### `(||)`
916−
917−``` purescript
918−(||) :: forall a. (Lattice a) => a -> a -> a
919−```
920−
921−The `sup` operator.
922−
923−#### `(&&)`
924−
925−``` purescript
926−(&&) :: forall a. (Lattice a) => a -> a -> a
927−```
928−
929−The `inf` operator.
930−
931−#### `BoundedLattice`
932−
933−``` purescript
934−class (Bounded a, Lattice a) <= BoundedLattice a where
935−```
936−
937−The `BoundedLattice` type class represents types that are finite
938−lattices.
939−
940−Instances should satisfy the following law in addition to the `Lattice`
941−and `Bounded` laws:
942−
943−- Identity:
944− - `a || bottom = a`
945− - `a && top = a`
946−- Annihiliation:
947− - `a || top = top`
948− - `a && bottom = bottom`
949−
950−#### `boundedLatticeBoolean`
951−
952−``` purescript
953−instance boundedLatticeBoolean :: BoundedLattice Boolean
954−```
955−
956−
957−#### `boundedLatticeUnit`
958−
959−``` purescript
960−instance boundedLatticeUnit :: BoundedLattice Unit
961−```
962−
963−
964−#### `ComplementedLattice`
965−
966−``` purescript
967−class (BoundedLattice a) <= ComplementedLattice a where
968− not :: a -> a
969−```
970−
971−The `ComplementedLattice` type class represents types that are lattices
972−where every member is also uniquely complemented.
973−
974−Instances should satisfy the following law in addition to the
975−`BoundedLattice` laws:
976−
977−- Complemented:
978− - `not a || a == top`
979− - `not a && a == bottom`
980−- Double negation:
981− - `not <<< not == id`
982−
983−#### `complementedLatticeBoolean`
984−
985−``` purescript
986−instance complementedLatticeBoolean :: ComplementedLattice Boolean
987−```
988−
989−
990−#### `complementedLatticeUnit`
991−
992−``` purescript
993−instance complementedLatticeUnit :: ComplementedLattice Unit
994−```
995−
996−
997−#### `DistributiveLattice`
998−
999−``` purescript
1000−class (Lattice a) <= DistributiveLattice a where
1001−```
1002−
1003−The `DistributiveLattice` type class represents types that are lattices
1004−where the `&&` and `||` distribute over each other.
1005−
1006−Instances should satisfy the following law in addition to the `Lattice`
1007−laws:
1008−
1009−- Distributivity: `x && (y || z) = (x && y) || (x && z)`
1010−
1011−#### `distributiveLatticeBoolean`
1012−
1013−``` purescript
1014−instance distributiveLatticeBoolean :: DistributiveLattice Boolean
1015−```
1016−
1017−
1018−#### `distributiveLatticeUnit`
1019−
1020−``` purescript
1021−instance distributiveLatticeUnit :: DistributiveLattice Unit
1022−```
1023−
1024−
1025−#### `BooleanAlgebra`
1026−
1027−``` purescript
1028−class (ComplementedLattice a, DistributiveLattice a) <= BooleanAlgebra a where
1029−```
1030−
1031−The `BooleanAlgebra` type class represents types that are Boolean
1032−algebras, also known as Boolean lattices.
1033−
1034−Instances should satisfy the `ComplementedLattice` and
1035−`DistributiveLattice` laws.
1036−
1037−#### `booleanAlgebraBoolean`
1038−
1039−``` purescript
1040−instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
1041−```
1042−
1043−
1044−#### `booleanAlgebraUnit`
1045−
1046−``` purescript
1047−instance booleanAlgebraUnit :: BooleanAlgebra Unit
1048−```
1049−
1050−
1051−#### `Show`
1052−
1053−``` purescript
1054−class Show a where
1055− show :: a -> String
1056−```
1057−
1058−The `Show` type class represents those types which can be converted into
1059−a human-readable `String` representation.
1060−
1061−While not required, it is recommended that for any expression `x`, the
1062−string `show x` be executable PureScript code which evaluates to the same
1063−value as the expression `x`.
1064−
1065−#### `showBoolean`
1066−
1067−``` purescript
1068−instance showBoolean :: Show Boolean
1069−```
1070−
1071−
1072−#### `showNumber`
1073−
1074−``` purescript
1075−instance showNumber :: Show Number
1076−```
1077−
1078−
1079−#### `showString`
1080−
1081−``` purescript
1082−instance showString :: Show String
1083−```
1084−
1085−
1086−#### `showUnit`
1087−
1088−``` purescript
1089−instance showUnit :: Show Unit
1090−```
1091−
1092−
1093−#### `showArray`
1094−
1095−``` purescript
1096−instance showArray :: (Show a) => Show [a]
1097−```
1098−
1099−
1100−#### `showOrdering`
1101−
1102−``` purescript
1103−instance showOrdering :: Show Ordering
1104−```
1105−
1106−
1107−
1108−## Module Data.Function
1109−
1110−#### `on`
1111−
1112−``` purescript
1113−on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
1114−```
1115−
1116−The `on` function is used to change the domain of a binary operator.
1117−
1118−For example, we can create a function which compares two records based on the values of their `x` properties:
1119−
1120−```purescript
1121−compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
1122−compareX = compare `on` _.x
1123−```
1124−
1125−#### `Fn0`
1126−
1127−``` purescript
1128−data Fn0 :: * -> *
1129−```
1130−
1131−A function of zero arguments
1132−
1133−#### `Fn1`
1134−
1135−``` purescript
1136−data Fn1 :: * -> * -> *
1137−```
1138−
1139−A function of one argument
1140−
1141−#### `Fn2`
1142−
1143−``` purescript
1144−data Fn2 :: * -> * -> * -> *
1145−```
1146−
1147−A function of two arguments
1148−
1149−#### `Fn3`
1150−
1151−``` purescript
1152−data Fn3 :: * -> * -> * -> * -> *
1153−```
1154−
1155−A function of three arguments
1156−
1157−#### `Fn4`
1158−
1159−``` purescript
1160−data Fn4 :: * -> * -> * -> * -> * -> *
1161−```
1162−
1163−A function of four arguments
1164−
1165−#### `Fn5`
1166−
1167−``` purescript
1168−data Fn5 :: * -> * -> * -> * -> * -> * -> *
1169−```
1170−
1171−A function of five arguments
1172−
1173−#### `Fn6`
1174−
1175−``` purescript
1176−data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
1177−```
1178−
1179−A function of six arguments
1180−
1181−#### `Fn7`
1182−
1183−``` purescript
1184−data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
1185−```
1186−
1187−A function of seven arguments
1188−
1189−#### `Fn8`
1190−
1191−``` purescript
1192−data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
1193−```
1194−
1195−A function of eight arguments
1196−
1197−#### `Fn9`
1198−
1199−``` purescript
1200−data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
1201−```
1202−
1203−A function of nine arguments
1204−
1205−#### `Fn10`
1206−
1207−``` purescript
1208−data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
1209−```
1210−
1211−A function of ten arguments
1212−
1213−#### `mkFn0`
1214−
1215−``` purescript
1216−mkFn0 :: forall a. (Unit -> a) -> Fn0 a
1217−```
1218−
1219−Create a function of no arguments
1220−
1221−#### `mkFn1`
1222−
1223−``` purescript
1224−mkFn1 :: forall a b. (a -> b) -> Fn1 a b
1225−```
1226−
1227−Create a function of one argument
1228−
1229−#### `mkFn2`
1230−
1231−``` purescript
1232−mkFn2 :: forall a b c. (a -> b -> c) -> Fn2 a b c
1233−```
1234−
1235−Create a function of two arguments from a curried function
1236−
1237−#### `mkFn3`
1238−
1239−``` purescript
1240−mkFn3 :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
1241−```
1242−
1243−Create a function of three arguments from a curried function
1244−
1245−#### `mkFn4`
1246−
1247−``` purescript
1248−mkFn4 :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
1249−```
1250−
1251−Create a function of four arguments from a curried function
1252−
1253−#### `mkFn5`
1254−
1255−``` purescript
1256−mkFn5 :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
1257−```
1258−
1259−Create a function of five arguments from a curried function
1260−
1261−#### `mkFn6`
1262−
1263−``` purescript
1264−mkFn6 :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
1265−```
1266−
1267−Create a function of six arguments from a curried function
1268−
1269−#### `mkFn7`
1270−
1271−``` purescript
1272−mkFn7 :: 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
1273−```
1274−
1275−Create a function of seven arguments from a curried function
1276−
1277−#### `mkFn8`
1278−
1279−``` purescript
1280−mkFn8 :: 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
1281−```
1282−
1283−Create a function of eight arguments from a curried function
1284−
1285−#### `mkFn9`
1286−
1287−``` purescript
1288−mkFn9 :: 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
1289−```
1290−
1291−Create a function of nine arguments from a curried function
1292−
1293−#### `mkFn10`
1294−
1295−``` purescript
1296−mkFn10 :: 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
1297−```
1298−
1299−Create a function of ten arguments from a curried function
1300−
1301−#### `runFn0`
1302−
1303−``` purescript
1304−runFn0 :: forall a. Fn0 a -> a
1305−```
1306−
1307−Apply a function of no arguments
1308−
1309−#### `runFn1`
1310−
1311−``` purescript
1312−runFn1 :: forall a b. Fn1 a b -> a -> b
1313−```
1314−
1315−Apply a function of one argument
1316−
1317−#### `runFn2`
1318−
1319−``` purescript
1320−runFn2 :: forall a b c. Fn2 a b c -> a -> b -> c
1321−```
1322−
1323−Apply a function of two arguments
1324−
1325−#### `runFn3`
1326−
1327−``` purescript
1328−runFn3 :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
1329−```
1330−
1331−Apply a function of three arguments
1332−
1333−#### `runFn4`
1334−
1335−``` purescript
1336−runFn4 :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
1337−```
1338−
1339−Apply a function of four arguments
1340−
1341−#### `runFn5`
1342−
1343−``` purescript
1344−runFn5 :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
1345−```
1346−
1347−Apply a function of five arguments
1348−
1349−#### `runFn6`
1350−
1351−``` purescript
1352−runFn6 :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
1353−```
1354−
1355−Apply a function of six arguments
1356−
1357−#### `runFn7`
1358−
1359−``` purescript
1360−runFn7 :: 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
1361−```
1362−
1363−Apply a function of seven arguments
1364−
1365−#### `runFn8`
1366−
1367−``` purescript
1368−runFn8 :: 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
1369−```
1370−
1371−Apply a function of eight arguments
1372−
1373−#### `runFn9`
1374−
1375−``` purescript
1376−runFn9 :: 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
1377−```
1378−
1379−Apply a function of nine arguments
1380−
1381−#### `runFn10`
1382−
1383−``` purescript
1384−runFn10 :: 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
1385−```
1386−
1387−Apply a function of ten arguments
1388−
1389−
1390−## Module Prelude.Unsafe
1391−
1392−#### `unsafeIndex`
1393−
1394−``` purescript
1395−unsafeIndex :: forall a. [a] -> Number -> a
1396−```
1397−
1398−Find the element of an array at the specified index.
1399−
1400−Note: this function can cause unpredictable failure at runtime if the index is out-of-bounds.
1401−
1402−
1403−## Module Control.Monad.Eff
1404−
1405−#### `Eff`
1406−
1407−``` purescript
1408−data Eff :: # ! -> * -> *
1409−```
1410−
1411−The `Eff` type constructor is used to represent _native_ effects.
1412−
1413−See [Handling Native Effects with the Eff Monad](https://github.com/purescript/purescript/wiki/Handling-Native-Effects-with-the-Eff-Monad) for more details.
1414−
1415−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.
1416−
1417−#### `Pure`
1418−
1419−``` purescript
1420−type Pure a = forall e. Eff e a
1421−```
1422−
1423−The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled.
1424−
1425−The `runPure` function can be used to run pure computations and obtain their result.
1426−
1427−#### `runPure`
1428−
1429−``` purescript
1430−runPure :: forall a. Pure a -> a
1431−```
1432−
1433−Run a pure computation and return its result.
1434−
1435−Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1436−is to use parentheses instead.
1437−
1438−#### `functorEff`
1439−
1440−``` purescript
1441−instance functorEff :: Functor (Eff e)
1442−```
1443−
1444−
1445−#### `applyEff`
1446−
1447−``` purescript
1448−instance applyEff :: Apply (Eff e)
1449−```
1450−
1451−
1452−#### `applicativeEff`
1453−
1454−``` purescript
1455−instance applicativeEff :: Applicative (Eff e)
1456−```
1457−
1458−
1459−#### `bindEff`
1460−
1461−``` purescript
1462−instance bindEff :: Bind (Eff e)
1463−```
1464−
1465−
1466−#### `monadEff`
1467−
1468−``` purescript
1469−instance monadEff :: Monad (Eff e)
1470−```
1471−
1472−
1473−#### `untilE`
1474−
1475−``` purescript
1476−untilE :: forall e. Eff e Boolean -> Eff e Unit
1477−```
1478−
1479−Loop until a condition becomes `true`.
1480−
1481−`untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
1482−until its return value is `true`.
1483−
1484−#### `whileE`
1485−
1486−``` purescript
1487−whileE :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
1488−```
1489−
1490−Loop while a condition is `true`.
1491−
1492−`whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
1493−`true`, it runs the effectful computation `m` and loops. If not, the computation ends.
1494−
1495−#### `forE`
1496−
1497−``` purescript
1498−forE :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
1499−```
1500−
1501−Loop over a consecutive collection of numbers.
1502−
1503−`forE lo hi f` runs the computation returned by the function `f` for each of the inputs
1504−between `lo` (inclusive) and `hi` (exclusive).
1505−
1506−#### `foreachE`
1507−
1508−``` purescript
1509−foreachE :: forall e a. [a] -> (a -> Eff e Unit) -> Eff e Unit
1510−```
1511−
1512−Loop over an array of values.
1513−
1514−`foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`.
1515−
1516−
1517−## Module Control.Monad.Eff.Unsafe
1518−
1519−#### `unsafeInterleaveEff`
1520−
1521−``` purescript
1522−unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
1523−```
1524−
1525−Change the type of an effectful computation, allowing it to be run in another context.
1526−
1527−Note: use of this function can result in arbitrary side-effects.
1528−
1529−
1530−## Module Debug.Trace
1531−
1532−#### `Trace`
1533−
1534−``` purescript
1535−data Trace :: !
1536−```
1537−
1538−The `Trace` effect represents those computations which write to the console.
1539−
1540−#### `trace`
1541−
1542−``` purescript
1543−trace :: forall r. String -> Eff (trace :: Trace | r) Unit
1544−```
1545−
1546−Write a `String` to the console.
1547−
1548−#### `print`
1549−
1550−``` purescript
1551−print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
1552−```
1553−
1554−Write a value to the console, using its `Show` instance to produce a `String`.
1555−
1556−
1557−## Module Control.Monad.ST
1558−
1559−#### `ST`
1560−
1561−``` purescript
1562−data ST :: * -> !
1563−```
1564−
1565−The `ST` effect represents _local mutation_, i.e. mutation which does not "escape" into the surrounding computation.
1566−
1567−An `ST` computation is parameterized by a phantom type which is used to restrict the set of reference cells it is allowed to access.
1568−
1569−The `runST` function can be used to handle the `ST` effect.
1570−
1571−#### `STRef`
1572−
1573−``` purescript
1574−data STRef :: * -> * -> *
1575−```
1576−
1577−The type `STRef s a` represents a mutable reference holding a value of type `a`, which can be used with the `ST s` effect.
1578−
1579−#### `newSTRef`
1580−
1581−``` purescript
1582−newSTRef :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1583−```
1584−
1585−Create a new mutable reference.
1586−
1587−#### `readSTRef`
1588−
1589−``` purescript
1590−readSTRef :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1591−```
1592−
1593−Read the current value of a mutable reference.
1594−
1595−#### `modifySTRef`
1596−
1597−``` purescript
1598−modifySTRef :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1599−```
1600−
1601−Modify the value of a mutable reference by applying a function to the current value.
1602−
1603−#### `writeSTRef`
1604−
1605−``` purescript
1606−writeSTRef :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1607−```
1608−
1609−Set the value of a mutable reference.
1610−
1611−#### `runST`
1612−
1613−``` purescript
1614−runST :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1615−```
1616−
1617−Run an `ST` computation.
1618−
1619−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
1620−to the surrounding computation.
1621−
1622−It may cause problems to apply this function using the `$` operator. The recommended approach is to use parentheses instead.
1623−
1624−#### `pureST`
1625−
1626−``` purescript
1627−pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
1628−```
1629−
1630−A convenience function which combines `runST` with `runPure`, which can be used when the only required effect is `ST`.
1631−
1632−Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1633−is to use parentheses instead.
1634−
1635−
1636−
prelude/images/Prelude.pngdeleted

Binary file not shown.

prelude/prelude.pursdeleted−1551
@@ -1,1551 +0,0 @@
1−module Prelude
2− ( Unit(..), unit
3− , ($), (#)
4− , flip
5− , const
6− , asTypeOf
7− , otherwise
8− , (:), cons
9− , Semigroupoid, (<<<), (>>>)
10− , Category, id
11− , Functor, (<$>), (<#>), void
12− , Apply, (<*>)
13− , Applicative, pure, liftA1
14− , Bind, (>>=)
15− , Monad, return, liftM1, ap
16− , Semigroup, (<>), (++)
17− , Semiring, (+), zero, (*), one
18− , ModuloSemiring, (/), mod
19− , Ring, (-), negate
20− , Num
21− , DivisionRing
22− , Eq, (==), (/=)
23− , Ordering(..), Ord, compare, (<), (>), (<=), (>=)
24− , Bounded, top, bottom
25− , Lattice, sup, inf, (||), (&&)
26− , BoundedLattice
27− , ComplementedLattice, not
28− , DistributiveLattice
29− , BooleanAlgebra
30− , Show, show
31− ) where
32−
33− -- | The `Unit` type has a single inhabitant, called `unit`. It represents
34− -- | values with no computational content.
35− -- |
36− -- | `Unit` is often used, wrapped in a monadic type constructor, as the
37− -- | return type of a computation where only
38− -- | the _effects_ are important.
39− newtype Unit = Unit {}
40−
41− -- | `unit` is the sole inhabitant of the `Unit` type.
42− unit :: Unit
43− unit = Unit {}
44−
45− infixr 0 $
46− infixl 0 #
47−
48− -- | Applies a function to its argument.
49− -- |
50− -- | ```purescript
51− -- | length $ groupBy productCategory $ filter isInStock $ products
52− -- | ```
53− -- |
54− -- | is equivalent to:
55− -- |
56− -- | ```purescript
57− -- | length (groupBy productCategory (filter isInStock products))
58− -- | ```
59− -- |
60− -- | `($)` is different from [`(#)`](#-2) because it is right-infix instead of
61− -- | left: `a $ b $ c $ d x = a $ (b $ (c $ (d $ x))) = a (b (c (d x)))`
62− ($) :: forall a b. (a -> b) -> a -> b
63− ($) f x = f x
64−
65− -- | Applies an argument to a function.
66− -- |
67− -- | ```purescript
68− -- | products # filter isInStock # groupBy productCategory # length
69− -- | ```
70− -- |
71− -- | is equivalent to:
72− -- |
73− -- | ```purescript
74− -- | length (groupBy productCategory (filter isInStock products))
75− -- | ```
76− -- |
77− -- | `(#)` is different from [`($)`](#-1) because it is left-infix instead of
78− -- | right: `x # a # b # c # d = (((x # a) # b) # c) # d = d (c (b (a x)))`
79− (#) :: forall a b. a -> (a -> b) -> b
80− (#) x f = f x
81−
82− -- | Flips the order of the arguments to a function of two arguments.
83− -- |
84− -- | ```purescript
85− -- | flip const 1 2 = const 2 1 = 2
86− -- | ```
87− flip :: forall a b c. (a -> b -> c) -> b -> a -> c
88− flip f b a = f a b
89−
90− -- | Returns its first argument and ignores its second.
91− -- |
92− -- | ```purescript
93− -- | const 1 "hello" = 1
94− -- | ```
95− const :: forall a b. a -> b -> a
96− const a _ = a
97−
98− -- | This function returns its first argument, and can be used to assert type
99− -- | equalities. This can be useful when types are otherwise ambiguous.
100− -- |
101− -- | ```purescript
102− -- | main = print $ [] `asTypeOf` [0]
103− -- | ```
104− -- |
105− -- | If instead, we had written `main = print []`, the type of the argument
106− -- | `[]` would have been ambiguous, resulting in a compile-time error.
107− asTypeOf :: forall a. a -> a -> a
108− asTypeOf x _ = x
109−
110− -- | An alias for `true`, which can be useful in guard clauses:
111− -- |
112− -- | ```purescript
113− -- | max x y | x >= y = x
114− -- | | otherwise = y
115− -- | ```
116− otherwise :: Boolean
117− otherwise = true
118−
119− -- | Attaches an element to the front of an array, creating a new array.
120− -- |
121− -- | ```purescript
122− -- | cons 1 [2, 3, 4] = [1, 2, 3, 4]
123− -- | ```
124− -- |
125− -- | Note, the running time of this function is `O(n)`.
126− foreign import cons
127− """
128− function cons(e) {
129− return function(l) {
130− return [e].concat(l);
131− };
132− }
133− """ :: forall a. a -> [a] -> [a]
134−
135− infixr 6 :
136−
137− -- | An infix alias for `cons`.
138− -- |
139− -- | Note, the running time of this function is `O(n)`.
140− (:) :: forall a. a -> [a] -> [a]
141− (:) = cons
142−
143− infixr 9 >>>
144− infixr 9 <<<
145−
146− -- | A `Semigroupoid` is similar to a [`Category`](#category) but does not
147− -- | require an identity element `id`, just composable morphisms.
148− -- |
149− -- | `Semigroupoid`s must satisfy the following law:
150− -- |
151− -- | - Associativity: `p <<< (q <<< r) = (p <<< q) <<< r`
152− -- |
153− -- | One example of a `Semigroupoid` is the function type constructor `(->)`,
154− -- | with `(<<<)` defined as function composition.
155− class Semigroupoid a where
156− (<<<) :: forall b c d. a c d -> a b c -> a b d
157−
158− instance semigroupoidArr :: Semigroupoid (->) where
159− (<<<) f g x = f (g x)
160−
161− -- | Forwards composition, or `(<<<)` with its arguments reversed.
162− (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
163− (>>>) f g = g <<< f
164−
165− -- | `Category`s consist of objects and composable morphisms between them, and
166− -- | as such are [`Semigroupoids`](#semigroupoid), but unlike `semigroupoids`
167− -- | must have an identity element.
168− -- |
169− -- | Instances must satisfy the following law in addition to the
170− -- | `Semigroupoid` law:
171− -- |
172− -- | - Identity: `id <<< p = p <<< id = p`
173− class (Semigroupoid a) <= Category a where
174− id :: forall t. a t t
175−
176− instance categoryArr :: Category (->) where
177− id x = x
178−
179− infixl 4 <$>
180− infixl 1 <#>
181−
182− -- | A `Functor` is a type constructor which supports a mapping operation
183− -- | `(<$>)`.
184− -- |
185− -- | `(<$>)` can be used to turn functions `a -> b` into functions
186− -- | `f a -> f b` whose argument and return types use the type constructor `f`
187− -- | to represent some computational context.
188− -- |
189− -- | Instances must satisfy the following laws:
190− -- |
191− -- | - Identity: `(<$>) id = id`
192− -- | - Composition: `(<$>) (f <<< g) = (f <$>) <<< (g <$>)`
193− class Functor f where
194− (<$>) :: forall a b. (a -> b) -> f a -> f b
195−
196− instance functorArr :: Functor ((->) r) where
197− (<$>) = (<<<)
198−
199− -- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
200− -- |
201− -- | ```purescript
202− -- | [1, 2, 3] <#> \n -> n * n
203− -- | ```
204− (<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
205− (<#>) fa f = f <$> fa
206−
207− -- | The `void` function is used to ignore the type wrapped by a
208− -- | [`Functor`](#functor), replacing it with `Unit` and keeping only the type
209− -- | information provided by the type constructor itself.
210− -- |
211− -- | `void` is often useful when using `do` notation to change the return type
212− -- | of a monadic computation:
213− -- |
214− -- | ```purescript
215− -- | main = forE 1 10 \n -> void do
216− -- | print n
217− -- | print (n * n)
218− -- | ```
219− void :: forall f a. (Functor f) => f a -> f Unit
220− void fa = const unit <$> fa
221−
222− infixl 4 <*>
223−
224− -- | The `Apply` class provides the `(<*>)` which is used to apply a function
225− -- | to an argument under a type constructor.
226− -- |
227− -- | `Apply` can be used to lift functions of two or more arguments to work on
228− -- | values wrapped with the type constructor `f`. It might also be understood
229− -- | in terms of the `lift2` function:
230− -- |
231− -- | ```purescript
232− -- | lift2 :: forall f a b c. (Apply f) => (a -> b -> c) -> f a -> f b -> f c
233− -- | lift2 f a b = f <$> a <*> b
234− -- | ```
235− -- |
236− -- | `(<*>)` is recovered from `lift2` as `lift2 ($)`. That is, `(<*>)` lifts
237− -- | the function application operator `($)` to arguments wrapped with the
238− -- | type constructor `f`.
239− -- |
240− -- | Instances must satisfy the following law in addition to the `Functor`
241− -- | laws:
242− -- |
243− -- | - Associative composition: `(<<<) <$> f <*> g <*> h = f <*> (g <*> h)`
244− -- |
245− -- | Formally, `Apply` represents a strong lax semi-monoidal endofunctor.
246− class (Functor f) <= Apply f where
247− (<*>) :: forall a b. f (a -> b) -> f a -> f b
248−
249− instance applyArr :: Apply ((->) r) where
250− (<*>) f g x = f x (g x)
251−
252− -- | The `Applicative` type class extends the [`Apply`](#apply) type class
253− -- | with a `pure` function, which can be used to create values of type `f a`
254− -- | from values of type `a`.
255− -- |
256− -- | Where [`Apply`](#apply) provides the ability to lift functions of two or
257− -- | more arguments to functions whose arguments are wrapped using `f`, and
258− -- | [`Functor`](#functor) provides the ability to lift functions of one
259− -- | argument, `pure` can be seen as the function which lifts functions of
260− -- | _zero_ arguments. That is, `Applicative` functors support a lifting
261− -- | operation for any number of function arguments.
262− -- |
263− -- | Instances must satisfy the following laws in addition to the `Apply`
264− -- | laws:
265− -- |
266− -- | - Identity: `(pure id) <*> v = v`
267− -- | - Composition: `(pure <<<) <*> f <*> g <*> h = f <*> (g <*> h)`
268− -- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
269− -- | - Interchange: `u <*> (pure y) = (pure ($ y)) <*> u`
270− class (Apply f) <= Applicative f where
271− pure :: forall a. a -> f a
272−
273− instance applicativeArr :: Applicative ((->) r) where
274− pure = const
275−
276− -- | `return` is an alias for `pure`.
277− return :: forall m a. (Applicative m) => a -> m a
278− return = pure
279−
280− -- | `liftA1` provides a default implementation of `(<$>)` for any
281− -- | [`Applicative`](#applicative) functor, without using `(<$>)` as provided
282− -- | by the [`Functor`](#functor)-[`Applicative`](#applicative) superclass
283− -- | relationship.
284− -- |
285− -- | `liftA1` can therefore be used to write [`Functor`](#functor) instances
286− -- | as follows:
287− -- |
288− -- | ```purescript
289− -- | instance functorF :: Functor F where
290− -- | (<$>) = liftA1
291− -- | ```
292− liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
293− liftA1 f a = pure f <*> a
294−
295− infixl 1 >>=
296−
297− -- | The `Bind` type class extends the [`Apply`](#apply) type class with a
298− -- | "bind" operation `(>>=)` which composes computations in sequence, using
299− -- | the return value of one computation to determine the next computation.
300− -- |
301− -- | The `>>=` operator can also be expressed using `do` notation, as follows:
302− -- |
303− -- | ```purescript
304− -- | x >>= f = do y <- x
305− -- | f y
306− -- | ```
307− -- |
308− -- | where the function argument of `f` is given the name `y`.
309− -- |
310− -- | Instances must satisfy the following law in addition to the `Apply`
311− -- | laws:
312− -- |
313− -- | - Associativity: `(x >>= f) >>= g = x >>= (\k => f k >>= g)`
314− -- |
315− -- | Associativity tells us that we can regroup operations which use `do`
316− -- | notation so that we can unambiguously write, for example:
317− -- |
318− -- | ```purescript
319− -- | do x <- m1
320− -- | y <- m2 x
321− -- | m3 x y
322− -- | ```
323− class (Apply m) <= Bind m where
324− (>>=) :: forall a b. m a -> (a -> m b) -> m b
325−
326− instance bindArr :: Bind ((->) r) where
327− (>>=) m f x = f (m x) x
328−
329− -- | The `Monad` type class combines the operations of the `Bind` and
330− -- | `Applicative` type classes. Therefore, `Monad` instances represent type
331− -- | constructors which support sequential composition, and also lifting of
332− -- | functions of arbitrary arity.
333− -- |
334− -- | Instances must satisfy the following laws in addition to the
335− -- | `Applicative` and `Bind` laws:
336− -- |
337− -- | - Left Identity: `pure x >>= f = f x`
338− -- | - Right Identity: `x >>= pure = x`
339− class (Applicative m, Bind m) <= Monad m
340−
341− instance monadArr :: Monad ((->) r)
342−
343− -- | `liftM1` provides a default implementation of `(<$>)` for any
344− -- | [`Monad`](#monad), without using `(<$>)` as provided by the
345− -- | [`Functor`](#functor)-[`Monad`](#monad) superclass relationship.
346− -- |
347− -- | `liftM1` can therefore be used to write [`Functor`](#functor) instances
348− -- | as follows:
349− -- |
350− -- | ```purescript
351− -- | instance functorF :: Functor F where
352− -- | (<$>) = liftM1
353− -- | ```
354− liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
355− liftM1 f a = do
356− a' <- a
357− return (f a')
358−
359− -- | `ap` provides a default implementation of `(<*>)` for any
360− -- | [`Monad`](#monad), without using `(<*>)` as provided by the
361− -- | [`Apply`](#apply)-[`Monad`](#monad) superclass relationship.
362− -- |
363− -- | `ap` can therefore be used to write [`Apply`](#apply) instances as
364− -- | follows:
365− -- |
366− -- | ```purescript
367− -- | instance applyF :: Apply F where
368− -- | (<*>) = ap
369− -- | ```
370− ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
371− ap f a = do
372− f' <- f
373− a' <- a
374− return (f' a')
375−
376− infixr 5 <>
377− infixr 5 ++
378−
379− -- | The `Semigroup` type class identifies an associative operation on a type.
380− -- |
381− -- | Instances are required to satisfy the following law:
382− -- |
383− -- | - Associativity: `(x <> y) <> z = x <> (y <> z)`
384− -- |
385− -- | One example of a `Semigroup` is `String`, with `(<>)` defined as string
386− -- | concatenation.
387− class Semigroup a where
388− (<>) :: a -> a -> a
389−
390− -- | `(++)` is an alias for `(<>)`.
391− (++) :: forall s. (Semigroup s) => s -> s -> s
392− (++) = (<>)
393−
394− instance semigroupString :: Semigroup String where
395− (<>) = concatString
396−
397− instance semigroupUnit :: Semigroup Unit where
398− (<>) _ _ = unit
399−
400− instance semigroupArr :: (Semigroup s') => Semigroup (s -> s') where
401− (<>) f g = \x -> f x <> g x
402−
403− instance semigroupOrdering :: Semigroup Ordering where
404− (<>) LT _ = LT
405− (<>) GT _ = GT
406− (<>) EQ y = y
407−
408− foreign import concatString
409− """
410− function concatString(s1) {
411− return function(s2) {
412− return s1 + s2;
413− };
414− }
415− """ :: String -> String -> String
416−
417− infixl 6 +
418− infixl 7 *
419−
420− -- | The `Semiring` class is for types that support an addition and
421− -- | multiplication operation.
422− -- |
423− -- | Instances must satisfy the following laws:
424− -- |
425− -- | - Commutative monoid under addition:
426− -- | - Associativity: `(a + b) + c = a + (b + c)`
427− -- | - Identity: `zero + a = a + zero = a`
428− -- | - Commutative: `a + b = b + a`
429− -- | - Monoid under multiplication:
430− -- | - Associativity: `(a * b) * c = a * (b * c)`
431− -- | - Identity: `one * a = a * one = a`
432− -- | - Multiplication distributes over addition:
433− -- | - Left distributivity: `a * (b + c) = (a * b) + (a * c)`
434− -- | - Right distributivity: `(a + b) * c = (a * c) + (b * c)`
435− -- | - Annihiliation: `zero * a = a * zero = zero`
436− class Semiring a where
437− (+) :: a -> a -> a
438− zero :: a
439− (*) :: a -> a -> a
440− one :: a
441−
442− instance semiringNumber :: Semiring Number where
443− (+) = numAdd
444− zero = 0
445− (*) = numMul
446− one = 1
447−
448− instance semiringUnit :: Semiring Unit where
449− (+) _ _ = unit
450− zero = unit
451− (*) _ _ = unit
452− one = unit
453−
454− infixl 6 -
455−
456− -- | The `Ring` class is for types that support addition, multiplication,
457− -- | and subtraction operations.
458− -- |
459− -- | Instances must satisfy the following law in addition to the `Semiring`
460− -- | laws:
461− -- |
462− -- | - Additive inverse: `a + (-a) = (-a) + a = zero`
463− class (Semiring a) <= Ring a where
464− (-) :: a -> a -> a
465−
466− instance ringNumber :: Ring Number where
467− (-) = numSub
468−
469− instance ringUnit :: Ring Unit where
470− (-) _ _ = unit
471−
472− negate :: forall a. (Ring a) => a -> a
473− negate a = zero - a
474−
475− infixl 7 /
476−
477− -- | The `ModuloSemiring` class is for types that support addition,
478− -- | multiplication, division, and modulo (division remainder) operations.
479− -- |
480− -- | Instances must satisfy the following law in addition to the `Semiring`
481− -- | laws:
482− -- |
483− -- | - Remainder: `a / b * b + (a `mod` b) = a`
484− class (Semiring a) <= ModuloSemiring a where
485− (/) :: a -> a -> a
486− mod :: a -> a -> a
487−
488− instance moduloSemiringNumber :: ModuloSemiring Number where
489− (/) = numDiv
490− mod _ _ = 0
491−
492− instance moduloSemiringUnit :: ModuloSemiring Unit where
493− (/) _ _ = unit
494− mod _ _ = unit
495−
496− -- | A `Ring` where every nonzero element has a multiplicative inverse.
497− -- |
498− -- | Instances must satisfy the following law in addition to the `Ring` and
499− -- | `ModuloSemiring` laws:
500− -- |
501− -- | - Multiplicative inverse: `(one / x) * x = one`
502− -- |
503− -- | As a consequence of this ```a `mod` b = zero``` as no divide operation
504− -- | will have a remainder.
505− class (Ring a, ModuloSemiring a) <= DivisionRing a
506−
507− instance divisionRingNumber :: DivisionRing Number
508−
509− instance divisionRingUnit :: DivisionRing Unit
510−
511− -- | The `Num` class is for types that are commutative fields.
512− -- |
513− -- | Instances must satisfy the following law in addition to the
514− -- | `DivisionRing` laws:
515− -- |
516− -- | - Commutative multiplication: `a * b = b * a`
517− class (DivisionRing a) <= Num a
518−
519− instance numNumber :: Num Number
520−
521− instance numUnit :: Num Unit
522−
523− foreign import numAdd
524− """
525− function numAdd(n1) {
526− return function(n2) {
527− return n1 + n2;
528− };
529− }
530− """ :: Number -> Number -> Number
531−
532− foreign import numMul
533− """
534− function numMul(n1) {
535− return function(n2) {
536− return n1 * n2;
537− };
538− }
539− """ :: Number -> Number -> Number
540−
541− foreign import numDiv
542− """
543− function numDiv(n1) {
544− return function(n2) {
545− return n1 / n2;
546− };
547− }
548− """ :: Number -> Number -> Number
549−
550− foreign import numSub
551− """
552− function numSub(n1) {
553− return function(n2) {
554− return n1 - n2;
555− };
556− }
557− """ :: Number -> Number -> Number
558−
559− infix 4 ==
560− infix 4 /=
561−
562− -- | The `Eq` type class represents types which support decidable equality.
563− -- |
564− -- | `Eq` instances should satisfy the following laws:
565− -- |
566− -- | - Reflexivity: `x == x = true`
567− -- | - Symmetry: `x == y = y == x`
568− -- | - Transitivity: if `x == y` and `y == z` then `x == z`
569− -- | - Negation: `x /= y = not (x == y)`
570− -- |
571− -- | `(/=)` may be implemented in terms of `(==)`, but it might give a performance improvement to implement it separately.
572− class Eq a where
573− (==) :: a -> a -> Boolean
574− (/=) :: a -> a -> Boolean
575−
576− instance eqBoolean :: Eq Boolean where
577− (==) = refEq
578− (/=) = refIneq
579−
580− instance eqNumber :: Eq Number where
581− (==) = refEq
582− (/=) = refIneq
583−
584− instance eqString :: Eq String where
585− (==) = refEq
586− (/=) = refIneq
587−
588− instance eqUnit :: Eq Unit where
589− (==) _ _ = true
590− (/=) _ _ = false
591−
592− instance eqArray :: (Eq a) => Eq [a] where
593− (==) = eqArrayImpl (==)
594− (/=) xs ys = not (xs == ys)
595−
596− instance eqOrdering :: Eq Ordering where
597− (==) LT LT = true
598− (==) GT GT = true
599− (==) EQ EQ = true
600− (==) _ _ = false
601− (/=) x y = not (x == y)
602−
603− foreign import refEq
604− """
605− function refEq(r1) {
606− return function(r2) {
607− return r1 === r2;
608− };
609− }
610− """ :: forall a. a -> a -> Boolean
611−
612− foreign import refIneq
613− """
614− function refIneq(r1) {
615− return function(r2) {
616− return r1 !== r2;
617− };
618− }
619− """ :: forall a. a -> a -> Boolean
620−
621− foreign import eqArrayImpl
622− """
623− function eqArrayImpl(f) {
624− return function(xs) {
625− return function(ys) {
626− if (xs.length !== ys.length) return false;
627− for (var i = 0; i < xs.length; i++) {
628− if (!f(xs[i])(ys[i])) return false;
629− }
630− return true;
631− };
632− };
633− }
634− """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
635−
636− -- | The `Ordering` data type represents the three possible outcomes of
637− -- | comparing two values:
638− -- |
639− -- | `LT` - The first value is _less than_ the second.
640− -- | `GT` - The first value is _greater than_ the second.
641− -- | `EQ` - The first value is _equal to_ or _incomparable to_ the second.
642− data Ordering = LT | GT | EQ
643−
644− -- | The `Ord` type class represents types which support comparisons.
645− -- |
646− -- | `Ord` instances should satisfy the laws of _partially orderings_:
647− -- |
648− -- | - Reflexivity: `a <= a`
649− -- | - Antisymmetry: if `a <= b` and `b <= a` then `a = b`
650− -- | - Transitivity: if `a <= b` and `b <= c` then `a <= c`
651− class (Eq a) <= Ord a where
652− compare :: a -> a -> Ordering
653−
654− instance ordBoolean :: Ord Boolean where
655− compare false false = EQ
656− compare false true = LT
657− compare true true = EQ
658− compare true false = GT
659−
660− instance ordNumber :: Ord Number where
661− compare = unsafeCompare
662−
663− instance ordString :: Ord String where
664− compare = unsafeCompare
665−
666− instance ordUnit :: Ord Unit where
667− compare _ _ = EQ
668−
669− instance ordArray :: (Ord a) => Ord [a] where
670− compare [] [] = EQ
671− compare [] _ = LT
672− compare _ [] = GT
673− compare (x:xs) (y:ys) = case compare x y of
674− EQ -> compare xs ys
675− other -> other
676−
677− instance ordOrdering :: Ord Ordering where
678− compare LT LT = EQ
679− compare EQ EQ = EQ
680− compare GT GT = EQ
681− compare LT _ = LT
682− compare EQ LT = GT
683− compare EQ GT = LT
684− compare GT _ = GT
685−
686− infixl 4 <
687− infixl 4 >
688− infixl 4 <=
689− infixl 4 >=
690−
691− -- | Test whether one value is _strictly less than_ another.
692− (<) :: forall a. (Ord a) => a -> a -> Boolean
693− (<) a1 a2 = case a1 `compare` a2 of
694− LT -> true
695− _ -> false
696−
697− -- | Test whether one value is _strictly greater than_ another.
698− (>) :: forall a. (Ord a) => a -> a -> Boolean
699− (>) a1 a2 = case a1 `compare` a2 of
700− GT -> true
701− _ -> false
702−
703− -- | Test whether one value is _non-strictly less than_ another.
704− (<=) :: forall a. (Ord a) => a -> a -> Boolean
705− (<=) a1 a2 = case a1 `compare` a2 of
706− GT -> false
707− _ -> true
708−
709− -- | Test whether one value is _non-strictly greater than_ another.
710− (>=) :: forall a. (Ord a) => a -> a -> Boolean
711− (>=) a1 a2 = case a1 `compare` a2 of
712− LT -> false
713− _ -> true
714−
715− unsafeCompare :: forall a. a -> a -> Ordering
716− unsafeCompare = unsafeCompareImpl LT EQ GT
717−
718− foreign import unsafeCompareImpl
719− """
720− function unsafeCompareImpl(lt) {
721− return function(eq) {
722− return function(gt) {
723− return function(x) {
724− return function(y) {
725− return x < y ? lt : x > y ? gt : eq;
726− };
727− };
728− };
729− };
730− }
731− """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
732−
733− -- | The `Bounded` type class represents types that are finite partially
734− -- | ordered sets.
735− -- |
736− -- | Instances should satisfy the following law in addition to the `Ord` laws:
737− -- |
738− -- | - Ordering: `bottom <= a <= top`
739− class (Ord a) <= Bounded a where
740− top :: a
741− bottom :: a
742−
743− instance boundedBoolean :: Bounded Boolean where
744− top = true
745− bottom = false
746−
747− instance boundedUnit :: Bounded Unit where
748− top = unit
749− bottom = unit
750−
751− instance boundedOrdering :: Bounded Ordering where
752− top = GT
753− bottom = LT
754−
755− -- | The `Lattice` type class represents types that are partially ordered
756− -- | sets with a supremum (`sup` or `||`) and infimum (`inf` or `&&`).
757− -- |
758− -- | Instances should satisfy the following laws in addition to the `Ord`
759− -- | laws:
760− -- |
761− -- | - Associativity:
762− -- | - `a || (b || c) = (a || b) || c`
763− -- | - `a && (b && c) = (a && b) && c`
764− -- | - Commutativity:
765− -- | - `a || b = b || a`
766− -- | - `a && b = b && a`
767− -- | - Absorption:
768− -- | - `a || (a && b) = a`
769− -- | - `a && (a || b) = a`
770− -- | - Idempotent:
771− -- | - `a || a = a`
772− -- | - `a && a = a`
773− class (Ord a) <= Lattice a where
774− sup :: a -> a -> a
775− inf :: a -> a -> a
776−
777− instance latticeBoolean :: Lattice Boolean where
778− sup = boolOr
779− inf = boolAnd
780−
781− instance latticeUnit :: Lattice Unit where
782− sup _ _ = unit
783− inf _ _ = unit
784−
785− infixr 2 ||
786− infixr 3 &&
787−
788− -- | The `sup` operator.
789− (||) :: forall a. (Lattice a) => a -> a -> a
790− (||) = sup
791−
792− -- | The `inf` operator.
793− (&&) :: forall a. (Lattice a) => a -> a -> a
794− (&&) = inf
795−
796− -- | The `BoundedLattice` type class represents types that are finite
797− -- | lattices.
798− -- |
799− -- | Instances should satisfy the following law in addition to the `Lattice`
800− -- | and `Bounded` laws:
801− -- |
802− -- | - Identity:
803− -- | - `a || bottom = a`
804− -- | - `a && top = a`
805− -- | - Annihiliation:
806− -- | - `a || top = top`
807− -- | - `a && bottom = bottom`
808− class (Bounded a, Lattice a) <= BoundedLattice a
809−
810− instance boundedLatticeBoolean :: BoundedLattice Boolean
811−
812− instance boundedLatticeUnit :: BoundedLattice Unit
813−
814− -- | The `ComplementedLattice` type class represents types that are lattices
815− -- | where every member is also uniquely complemented.
816− -- |
817− -- | Instances should satisfy the following law in addition to the
818− -- | `BoundedLattice` laws:
819− -- |
820− -- | - Complemented:
821− -- | - `not a || a == top`
822− -- | - `not a && a == bottom`
823− -- | - Double negation:
824− -- | - `not <<< not == id`
825− class (BoundedLattice a) <= ComplementedLattice a where
826− not :: a -> a
827−
828− instance complementedLatticeBoolean :: ComplementedLattice Boolean where
829− not = boolNot
830−
831− instance complementedLatticeUnit :: ComplementedLattice Unit where
832− not _ = unit
833−
834− -- | The `DistributiveLattice` type class represents types that are lattices
835− -- | where the `&&` and `||` distribute over each other.
836− -- |
837− -- | Instances should satisfy the following law in addition to the `Lattice`
838− -- | laws:
839− -- |
840− -- | - Distributivity: `x && (y || z) = (x && y) || (x && z)`
841− class (Lattice a) <= DistributiveLattice a
842−
843− instance distributiveLatticeBoolean :: DistributiveLattice Boolean
844−
845− instance distributiveLatticeUnit :: DistributiveLattice Unit
846−
847− -- | The `BooleanAlgebra` type class represents types that are Boolean
848− -- | algebras, also known as Boolean lattices.
849− -- |
850− -- | Instances should satisfy the `ComplementedLattice` and
851− -- | `DistributiveLattice` laws.
852− class (ComplementedLattice a, DistributiveLattice a) <= BooleanAlgebra a
853−
854− instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
855−
856− instance booleanAlgebraUnit :: BooleanAlgebra Unit
857−
858− foreign import boolOr
859− """
860− function boolOr(b1) {
861− return function(b2) {
862− return b1 || b2;
863− };
864− }
865− """ :: Boolean -> Boolean -> Boolean
866−
867− foreign import boolAnd
868− """
869− function boolAnd(b1) {
870− return function(b2) {
871− return b1 && b2;
872− };
873− }
874− """ :: Boolean -> Boolean -> Boolean
875−
876− foreign import boolNot
877− """
878− function boolNot(b) {
879− return !b;
880− }
881− """ :: Boolean -> Boolean
882−
883− -- | The `Show` type class represents those types which can be converted into
884− -- | a human-readable `String` representation.
885− -- |
886− -- | While not required, it is recommended that for any expression `x`, the
887− -- | string `show x` be executable PureScript code which evaluates to the same
888− -- | value as the expression `x`.
889− class Show a where
890− show :: a -> String
891−
892− instance showBoolean :: Show Boolean where
893− show true = "true"
894− show false = "false"
895−
896− instance showNumber :: Show Number where
897− show = showNumberImpl
898−
899− instance showString :: Show String where
900− show = showStringImpl
901−
902− instance showUnit :: Show Unit where
903− show _ = "unit"
904−
905− instance showArray :: (Show a) => Show [a] where
906− show = showArrayImpl show
907−
908− instance showOrdering :: Show Ordering where
909− show LT = "LT"
910− show GT = "GT"
911− show EQ = "EQ"
912−
913− foreign import showNumberImpl
914− """
915− function showNumberImpl(n) {
916− return n.toString();
917− }
918− """ :: Number -> String
919−
920− foreign import showStringImpl
921− """
922− function showStringImpl(s) {
923− return JSON.stringify(s);
924− }
925− """ :: String -> String
926−
927− foreign import showArrayImpl
928− """
929− function showArrayImpl(f) {
930− return function(xs) {
931− var ss = [];
932− for (var i = 0, l = xs.length; i < l; i++) {
933− ss[i] = f(xs[i]);
934− }
935− return '[' + ss.join(',') + ']';
936− };
937− }
938− """ :: forall a. (a -> String) -> [a] -> String
939−
940−module Data.Function where
941−
942− -- | The `on` function is used to change the domain of a binary operator.
943− -- |
944− -- | For example, we can create a function which compares two records based on the values of their `x` properties:
945− -- |
946− -- | ```purescript
947− -- | compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
948− -- | compareX = compare `on` _.x
949− -- | ```
950− on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
951− on f g x y = g x `f` g y
952−
953− -- | A function of zero arguments
954− foreign import data Fn0 :: * -> *
955−
956− -- | A function of one argument
957− foreign import data Fn1 :: * -> * -> *
958−
959− -- | A function of two arguments
960− foreign import data Fn2 :: * -> * -> * -> *
961−
962− -- | A function of three arguments
963− foreign import data Fn3 :: * -> * -> * -> * -> *
964−
965− -- | A function of four arguments
966− foreign import data Fn4 :: * -> * -> * -> * -> * -> *
967−
968− -- | A function of five arguments
969− foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
970−
971− -- | A function of six arguments
972− foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
973−
974− -- | A function of seven arguments
975− foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
976−
977− -- | A function of eight arguments
978− foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
979−
980− -- | A function of nine arguments
981− foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
982−
983− -- | A function of ten arguments
984− foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
985−
986− -- | Create a function of no arguments
987− foreign import mkFn0
988− """
989− function mkFn0(fn) {
990− return function() {
991− return fn({});
992− };
993− }
994− """ :: forall a. (Unit -> a) -> Fn0 a
995−
996− -- | Create a function of one argument
997− foreign import mkFn1
998− """
999− function mkFn1(fn) {
1000− return function(a) {
1001− return fn(a);
1002− };
1003− }
1004− """ :: forall a b. (a -> b) -> Fn1 a b
1005−
1006− -- | Create a function of two arguments from a curried function
1007− foreign import mkFn2
1008− """
1009− function mkFn2(fn) {
1010− return function(a, b) {
1011− return fn(a)(b);
1012− };
1013− }
1014− """ :: forall a b c. (a -> b -> c) -> Fn2 a b c
1015−
1016− -- | Create a function of three arguments from a curried function
1017− foreign import mkFn3
1018− """
1019− function mkFn3(fn) {
1020− return function(a, b, c) {
1021− return fn(a)(b)(c);
1022− };
1023− }
1024− """ :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
1025−
1026− -- | Create a function of four arguments from a curried function
1027− foreign import mkFn4
1028− """
1029− function mkFn4(fn) {
1030− return function(a, b, c, d) {
1031− return fn(a)(b)(c)(d);
1032− };
1033− }
1034− """ :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
1035−
1036− -- | Create a function of five arguments from a curried function
1037− foreign import mkFn5
1038− """
1039− function mkFn5(fn) {
1040− return function(a, b, c, d, e) {
1041− return fn(a)(b)(c)(d)(e);
1042− };
1043− }
1044− """ :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
1045−
1046− -- | Create a function of six arguments from a curried function
1047− foreign import mkFn6
1048− """
1049− function mkFn6(fn) {
1050− return function(a, b, c, d, e, f) {
1051− return fn(a)(b)(c)(d)(e)(f);
1052− };
1053− }
1054− """ :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
1055−
1056− -- | Create a function of seven arguments from a curried function
1057− foreign import mkFn7
1058− """
1059− function mkFn7(fn) {
1060− return function(a, b, c, d, e, f, g) {
1061− return fn(a)(b)(c)(d)(e)(f)(g);
1062− };
1063− }
1064− """ :: 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
1065−
1066− -- | Create a function of eight arguments from a curried function
1067− foreign import mkFn8
1068− """
1069− function mkFn8(fn) {
1070− return function(a, b, c, d, e, f, g, h) {
1071− return fn(a)(b)(c)(d)(e)(f)(g)(h);
1072− };
1073− }
1074− """ :: 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
1075−
1076− -- | Create a function of nine arguments from a curried function
1077− foreign import mkFn9
1078− """
1079− function mkFn9(fn) {
1080− return function(a, b, c, d, e, f, g, h, i) {
1081− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i);
1082− };
1083− }
1084− """ :: 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
1085−
1086− -- | Create a function of ten arguments from a curried function
1087− foreign import mkFn10
1088− """
1089− function mkFn10(fn) {
1090− return function(a, b, c, d, e, f, g, h, i, j) {
1091− return fn(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);
1092− };
1093− }
1094− """ :: 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
1095−
1096− -- | Apply a function of no arguments
1097− foreign import runFn0
1098− """
1099− function runFn0(fn) {
1100− return fn();
1101− }
1102− """ :: forall a. Fn0 a -> a
1103−
1104− -- | Apply a function of one argument
1105− foreign import runFn1
1106− """
1107− function runFn1(fn) {
1108− return function(a) {
1109− return fn(a);
1110− };
1111− }
1112− """ :: forall a b. Fn1 a b -> a -> b
1113−
1114− -- | Apply a function of two arguments
1115− foreign import runFn2
1116− """
1117− function runFn2(fn) {
1118− return function(a) {
1119− return function(b) {
1120− return fn(a, b);
1121− };
1122− };
1123− }
1124− """ :: forall a b c. Fn2 a b c -> a -> b -> c
1125−
1126− -- | Apply a function of three arguments
1127− foreign import runFn3
1128− """
1129− function runFn3(fn) {
1130− return function(a) {
1131− return function(b) {
1132− return function(c) {
1133− return fn(a, b, c);
1134− };
1135− };
1136− };
1137− }
1138− """ :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
1139−
1140− -- | Apply a function of four arguments
1141− foreign import runFn4
1142− """
1143− function runFn4(fn) {
1144− return function(a) {
1145− return function(b) {
1146− return function(c) {
1147− return function(d) {
1148− return fn(a, b, c, d);
1149− };
1150− };
1151− };
1152− };
1153− }
1154− """ :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
1155−
1156− -- | Apply a function of five arguments
1157− foreign import runFn5
1158− """
1159− function runFn5(fn) {
1160− return function(a) {
1161− return function(b) {
1162− return function(c) {
1163− return function(d) {
1164− return function(e) {
1165− return fn(a, b, c, d, e);
1166− };
1167− };
1168− };
1169− };
1170− };
1171− }
1172− """ :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
1173−
1174− -- | Apply a function of six arguments
1175− foreign import runFn6
1176− """
1177− function runFn6(fn) {
1178− return function(a) {
1179− return function(b) {
1180− return function(c) {
1181− return function(d) {
1182− return function(e) {
1183− return function(f) {
1184− return fn(a, b, c, d, e, f);
1185− };
1186− };
1187− };
1188− };
1189− };
1190− };
1191− }
1192− """ :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
1193−
1194− -- | Apply a function of seven arguments
1195− foreign import runFn7
1196− """
1197− function runFn7(fn) {
1198− return function(a) {
1199− return function(b) {
1200− return function(c) {
1201− return function(d) {
1202− return function(e) {
1203− return function(f) {
1204− return function(g) {
1205− return fn(a, b, c, d, e, f, g);
1206− };
1207− };
1208− };
1209− };
1210− };
1211− };
1212− };
1213− }
1214− """ :: 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
1215−
1216− -- | Apply a function of eight arguments
1217− foreign import runFn8
1218− """
1219− function runFn8(fn) {
1220− return function(a) {
1221− return function(b) {
1222− return function(c) {
1223− return function(d) {
1224− return function(e) {
1225− return function(f) {
1226− return function(g) {
1227− return function(h) {
1228− return fn(a, b, c, d, e, f, g, h);
1229− };
1230− };
1231− };
1232− };
1233− };
1234− };
1235− };
1236− };
1237− }
1238− """ :: 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
1239−
1240− -- | Apply a function of nine arguments
1241− foreign import runFn9
1242− """
1243− function runFn9(fn) {
1244− return function(a) {
1245− return function(b) {
1246− return function(c) {
1247− return function(d) {
1248− return function(e) {
1249− return function(f) {
1250− return function(g) {
1251− return function(h) {
1252− return function(i) {
1253− return fn(a, b, c, d, e, f, g, h, i);
1254− };
1255− };
1256− };
1257− };
1258− };
1259− };
1260− };
1261− };
1262− };
1263− }
1264− """ :: 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
1265−
1266− -- | Apply a function of ten arguments
1267− foreign import runFn10
1268− """
1269− function runFn10(fn) {
1270− return function(a) {
1271− return function(b) {
1272− return function(c) {
1273− return function(d) {
1274− return function(e) {
1275− return function(f) {
1276− return function(g) {
1277− return function(h) {
1278− return function(i) {
1279− return function(j) {
1280− return fn(a, b, c, d, e, f, g, h, i, j);
1281− };
1282− };
1283− };
1284− };
1285− };
1286− };
1287− };
1288− };
1289− };
1290− };
1291− }
1292− """ :: 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
1293−
1294−module Prelude.Unsafe where
1295−
1296− -- | Find the element of an array at the specified index.
1297− -- |
1298− -- | Note: this function can cause unpredictable failure at runtime if the index is out-of-bounds.
1299− foreign import unsafeIndex
1300− """
1301− function unsafeIndex(xs) {
1302− return function(n) {
1303− return xs[n];
1304− };
1305− }
1306− """ :: forall a. [a] -> Number -> a
1307−
1308−module Control.Monad.Eff
1309− ( Eff()
1310− , Pure()
1311− , runPure
1312− , untilE, whileE, forE, foreachE
1313− ) where
1314−
1315− -- | The `Eff` type constructor is used to represent _native_ effects.
1316− -- |
1317− -- | See [Handling Native Effects with the Eff Monad](https://github.com/purescript/purescript/wiki/Handling-Native-Effects-with-the-Eff-Monad) for more details.
1318− -- |
1319− -- | 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.
1320− foreign import data Eff :: # ! -> * -> *
1321−
1322− foreign import returnE
1323− """
1324− function returnE(a) {
1325− return function() {
1326− return a;
1327− };
1328− }
1329− """ :: forall e a. a -> Eff e a
1330−
1331− foreign import bindE
1332− """
1333− function bindE(a) {
1334− return function(f) {
1335− return function() {
1336− return f(a())();
1337− };
1338− };
1339− }
1340− """ :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
1341−
1342− -- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled.
1343− -- |
1344− -- | The `runPure` function can be used to run pure computations and obtain their result.
1345− type Pure a = forall e. Eff e a
1346−
1347− -- | Run a pure computation and return its result.
1348− -- |
1349− -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1350− -- | is to use parentheses instead.
1351− foreign import runPure
1352− """
1353− function runPure(f) {
1354− return f();
1355− }
1356− """ :: forall a. Pure a -> a
1357−
1358− instance functorEff :: Functor (Eff e) where
1359− (<$>) = liftA1
1360−
1361− instance applyEff :: Apply (Eff e) where
1362− (<*>) = ap
1363−
1364− instance applicativeEff :: Applicative (Eff e) where
1365− pure = returnE
1366−
1367− instance bindEff :: Bind (Eff e) where
1368− (>>=) = bindE
1369−
1370− instance monadEff :: Monad (Eff e)
1371−
1372− -- | Loop until a condition becomes `true`.
1373− -- |
1374− -- | `untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
1375− -- | until its return value is `true`.
1376− foreign import untilE
1377− """
1378− function untilE(f) {
1379− return function() {
1380− while (!f());
1381− return {};
1382− };
1383− }
1384− """ :: forall e. Eff e Boolean -> Eff e Unit
1385−
1386− -- | Loop while a condition is `true`.
1387− -- |
1388− -- | `whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
1389− -- | `true`, it runs the effectful computation `m` and loops. If not, the computation ends.
1390− foreign import whileE
1391− """
1392− function whileE(f) {
1393− return function(a) {
1394− return function() {
1395− while (f()) {
1396− a();
1397− }
1398− return {};
1399− };
1400− };
1401− }
1402− """ :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
1403−
1404− -- | Loop over a consecutive collection of numbers.
1405− -- |
1406− -- | `forE lo hi f` runs the computation returned by the function `f` for each of the inputs
1407− -- | between `lo` (inclusive) and `hi` (exclusive).
1408− foreign import forE
1409− """
1410− function forE(lo) {
1411− return function(hi) {
1412− return function(f) {
1413− return function() {
1414− for (var i = lo; i < hi; i++) {
1415− f(i)();
1416− }
1417− };
1418− };
1419− };
1420− }
1421− """ :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
1422−
1423− -- | Loop over an array of values.
1424− -- |
1425− -- | `foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`.
1426− foreign import foreachE
1427− """
1428− function foreachE(as) {
1429− return function(f) {
1430− return function() {
1431− for (var i = 0; i < as.length; i++) {
1432− f(as[i])();
1433− }
1434− };
1435− };
1436− }
1437− """ :: forall e a. [a] -> (a -> Eff e Unit) -> Eff e Unit
1438−
1439−module Control.Monad.Eff.Unsafe where
1440−
1441− import Control.Monad.Eff
1442−
1443− -- | Change the type of an effectful computation, allowing it to be run in another context.
1444− -- |
1445− -- | Note: use of this function can result in arbitrary side-effects.
1446− foreign import unsafeInterleaveEff
1447− """
1448− function unsafeInterleaveEff(f) {
1449− return f;
1450− }
1451− """ :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
1452−
1453−module Debug.Trace where
1454−
1455− import Control.Monad.Eff
1456−
1457− -- | The `Trace` effect represents those computations which write to the console.
1458− foreign import data Trace :: !
1459−
1460− -- | Write a `String` to the console.
1461− foreign import trace
1462− """
1463− function trace(s) {
1464− return function() {
1465− console.log(s);
1466− return {};
1467− };
1468− }
1469− """ :: forall r. String -> Eff (trace :: Trace | r) Unit
1470−
1471− -- | Write a value to the console, using its `Show` instance to produce a `String`.
1472− print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
1473− print o = trace (show o)
1474−
1475−module Control.Monad.ST where
1476−
1477− import Control.Monad.Eff
1478−
1479− -- | The `ST` effect represents _local mutation_, i.e. mutation which does not "escape" into the surrounding computation.
1480− -- |
1481− -- | An `ST` computation is parameterized by a phantom type which is used to restrict the set of reference cells it is allowed to access.
1482− -- |
1483− -- | The `runST` function can be used to handle the `ST` effect.
1484− foreign import data ST :: * -> !
1485−
1486− -- | The type `STRef s a` represents a mutable reference holding a value of type `a`, which can be used with the `ST s` effect.
1487− foreign import data STRef :: * -> * -> *
1488−
1489− -- | Create a new mutable reference.
1490− foreign import newSTRef
1491− """
1492− function newSTRef(val) {
1493− return function() {
1494− return { value: val };
1495− };
1496− }
1497− """ :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1498−
1499− -- | Read the current value of a mutable reference.
1500− foreign import readSTRef
1501− """
1502− function readSTRef(ref) {
1503− return function() {
1504− return ref.value;
1505− };
1506− }
1507− """ :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1508−
1509− -- | Modify the value of a mutable reference by applying a function to the current value.
1510− foreign import modifySTRef
1511− """
1512− function modifySTRef(ref) {
1513− return function(f) {
1514− return function() {
1515− return ref.value = f(ref.value);
1516− };
1517− };
1518− }
1519− """ :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1520−
1521− -- | Set the value of a mutable reference.
1522− foreign import writeSTRef
1523− """
1524− function writeSTRef(ref) {
1525− return function(a) {
1526− return function() {
1527− return ref.value = a;
1528− };
1529− };
1530− }
1531− """ :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1532−
1533− -- | Run an `ST` computation.
1534− -- |
1535− -- | 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
1536− -- | to the surrounding computation.
1537− -- |
1538− -- | It may cause problems to apply this function using the `$` operator. The recommended approach is to use parentheses instead.
1539− foreign import runST
1540− """
1541− function runST(f) {
1542− return f;
1543− }
1544− """ :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1545−
1546− -- | A convenience function which combines `runST` with `runPure`, which can be used when the only required effect is `ST`.
1547− -- |
1548− -- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
1549− -- | is to use parentheses instead.
1550− pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
1551− pureST st = runPure (runST st)
prelude/updateDocs.shdeleted−11
@@ -1,11 +0,0 @@
1−../dist/build/psc-docs/psc-docs prelude.purs > README.md
2−../dist/build/psc-hierarchy/psc-hierarchy prelude.purs -o prelude
3−
4−mkdir -p images
5−
6−for f in prelude/*; do
7− BASE=$(basename "$f")
8− dot -Tpng -o images/"$BASE".png "$f"
9−done
10−
11−rm -r prelude
psc-make/Main.hs+2−4
@@ -49,9 +49,7 @@ data InputOptions = InputOptions
4949 }
5050
5151readInput :: InputOptions -> IO [(Either P.RebuildPolicy FilePath, String)]
52−readInput InputOptions{..} = do
53− content <- forM ioInputFiles $ \inFile -> (Right inFile, ) <$> readFile inFile
54− return (if ioNoPrelude then content else (Left P.RebuildNever, P.prelude) : content)
52+readInput InputOptions{..} = forM ioInputFiles $ \inFile -> (Right inFile, ) <$> readFile inFile
5553
5654newtype Make a = Make { unMake :: ReaderT (P.Options P.Make) (WriterT P.MultipleErrors (ExceptT P.MultipleErrors IO)) a }
5755 deriving (Functor, Applicative, Monad, MonadIO, MonadError P.MultipleErrors, MonadWriter P.MultipleErrors, MonadReader (P.Options P.Make))
@@ -123,7 +121,7 @@ noTco = switch $
123121noPrelude :: Parser Bool
124122noPrelude = switch $
125123 long "no-prelude"
126− <> help "Omit the Prelude"
124+ <> help "Omit the automatic Prelude import"
127125
128126noMagicDo :: Parser Bool
129127noMagicDo = switch $
psc/Main.hs+2−3
@@ -51,8 +51,7 @@ data InputOptions = InputOptions
5151readInput :: InputOptions -> IO [(Maybe FilePath, String)]
5252readInput InputOptions{..}
5353 | ioUseStdIn = return . (Nothing ,) <$> getContents
54− | otherwise = do content <- forM ioInputFiles $ \inFile -> (Just inFile, ) <$> readFile inFile
55− return (if ioNoPrelude then content else (Nothing, P.prelude) : content)
54+ | otherwise = forM ioInputFiles $ \inFile -> (Just inFile, ) <$> readFile inFile
5655
5756type PSC = ReaderT (P.Options P.Compile) (WriterT P.MultipleErrors (Either P.MultipleErrors))
5857
@@ -143,7 +142,7 @@ noTco = switch $
143142noPrelude :: Parser Bool
144143noPrelude = switch $
145144 long "no-prelude"
146− <> help "Omit the Prelude"
145+ <> help "Omit the automatic Prelude import"
147146
148147comments :: Parser Bool
149148comments = switch $
psci/PSCi.hs+1−1
@@ -101,7 +101,7 @@ loadAllModules files = do
101101 filesAndContent <- forM files $ \filename -> do
102102 content <- readFile filename
103103 return (Right filename, content)
104− return $ P.parseModulesFromFiles (either (const "") id) $ (Left P.RebuildNever, P.prelude) : filesAndContent
104+ return $ P.parseModulesFromFiles (either (const "") id) filesAndContent
105105
106106-- |
107107-- Load all modules, updating the application state
purescript.cabal−1
@@ -34,7 +34,6 @@ library
3434 transformers >= 0.4.0 && < 0.5,
3535 utf8-string >= 1 && < 2,
3636 pattern-arrows >= 0.0.2 && < 0.1,
37− file-embed >= 0.0.7 && < 0.0.8,
3837 time -any,
3938 boxes >= 0.1.4 && < 0.2.0
4039 exposed-modules: Language.PureScript
src/Language/PureScript.hs−6
@@ -26,18 +26,15 @@ module Language.PureScript
2626 , RebuildPolicy(..)
2727 , MonadMake(..)
2828 , make
29− , prelude
3029 , version
3130 ) where
3231
33−import Data.FileEmbed (embedFile)
3432import Data.Function (on)
3533import Data.List (sortBy, groupBy, intercalate)
3634import Data.Maybe (fromMaybe)
3735import Data.Time.Clock
3836import Data.Version (Version)
3937import qualified Data.Traversable as T (traverse)
40−import qualified Data.ByteString.UTF8 as BU
4138import qualified Data.Map as M
4239import qualified Data.Set as S
4340
@@ -274,8 +271,5 @@ importPrim = addDefaultImport (ModuleName [ProperName C.prim])
274271importPrelude :: Module -> Module
275272importPrelude = addDefaultImport (ModuleName [ProperName C.prelude])
276273
277−prelude :: String
278−prelude = BU.toString $(embedFile "prelude/prelude.purs")
279−
280274version :: Version
281275version = Paths.version
tests/Main.hs+5−1
@@ -31,6 +31,10 @@ import System.FilePath (pathSeparator)
3131import System.Directory (getCurrentDirectory, getTemporaryDirectory, getDirectoryContents, findExecutable)
3232import Text.Parsec (ParseError)
3333
34+-- TODO : embed a minimal prelude?
35+prelude :: String
36+prelude = "module Prelude where"
37+
3438readInput :: [FilePath] -> IO [(FilePath, String)]
3539readInput inputFiles = forM inputFiles $ \inputFile -> do
3640 text <- readFile inputFile
@@ -38,7 +42,7 @@ readInput inputFiles = forM inputFiles $ \inputFile -> do
3842
3943loadPrelude :: Either P.MultipleErrors (String, String, P.Environment)
4044loadPrelude =
41− case P.parseModulesFromFiles id [("", P.prelude)] of
45+ case P.parseModulesFromFiles id [("", prelude)] of
4246 Left parseError -> Left . P.errorMessage . P.ErrorParsingPrelude $ parseError
4347 Right ms -> fmap fst . runWriterT $ runReaderT (P.compile (map snd ms) []) (P.defaultCompileOptions { P.optionsAdditional = P.CompileOptions "Tests" [] [] })
4448