git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1058 from purescript/0.7-dev
8cf3d51Phil Freeman
examples/failing/438.pursnew file+9
@@ -0,0 +1,9 @@
1+module Main where
2+
3+data Fix f = In (f (Fix f))
4+
5+instance eqFix :: (Eq (f (Fix f))) => Eq (Fix f) where
6+ (==) (In f) (In g) = f == g
7+ (/=) a b = not (a == b)
8+
9+example = In [] == In []
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/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+10−9
@@ -21,6 +21,7 @@ import Control.Monad
21import Control.Monad.Error.Class (MonadError(..))
21import Control.Monad.Error.Class (MonadError(..))
22import Control.Monad.Trans.Except
22import Control.Monad.Trans.Except
23import Control.Monad.Reader
23import Control.Monad.Reader
24+import Control.Monad.Writer
24
25
25import Data.Version (showVersion)
26import Data.Version (showVersion)
26import Data.Traversable (traverse)
27import Data.Traversable (traverse)
@@ -50,15 +51,13 @@ data InputOptions = InputOptions
50 }
51 }
51
52
52readInput :: InputOptions -> IO [(Either P.RebuildPolicy FilePath, String)]
53readInput :: InputOptions -> IO [(Either P.RebuildPolicy FilePath, String)]
53−readInput InputOptions{..} = do
54− content <- forM ioInputFiles $ \inFile -> (Right inFile, ) <$> readFile inFile
54+readInput InputOptions{..} = forM ioInputFiles $ \inFile -> (Right inFile, ) <$> readFile inFile
55− return (if ioNoPrelude then content else (Left P.RebuildNever, P.prelude) : content)
56
55
57−newtype Make a = Make { unMake :: ReaderT (P.Options P.Make) (ExceptT P.MultipleErrors IO) a }
56+newtype Make a = Make { unMake :: ReaderT (P.Options P.Make) (WriterT P.MultipleErrors (ExceptT P.MultipleErrors IO)) a }
58− deriving (Functor, Applicative, Monad, MonadIO, MonadError P.MultipleErrors, MonadReader (P.Options P.Make))
57+ deriving (Functor, Applicative, Monad, MonadIO, MonadError P.MultipleErrors, MonadWriter P.MultipleErrors, MonadReader (P.Options P.Make))
59
58
60−runMake :: P.Options P.Make -> Make a -> IO (Either P.MultipleErrors a)
59+runMake :: P.Options P.Make -> Make a -> IO (Either P.MultipleErrors (a, P.MultipleErrors))
61−runMake opts = runExceptT . flip runReaderT opts . unMake
60+runMake opts = runExceptT . runWriterT . flip runReaderT opts . unMake
62
61
63makeIO :: (IOError -> P.ErrorMessage) -> IO a -> Make a
62makeIO :: (IOError -> P.ErrorMessage) -> IO a -> Make a
64makeIO f io = do
63makeIO f io = do
@@ -91,7 +90,9 @@ compile (PSCMakeOptions input outputDir opts usePrefix) = do
91 Left errs -> do
90 Left errs -> do
92 putStrLn (P.prettyPrintMultipleErrors (P.optionsVerboseErrors opts) errs)
91 putStrLn (P.prettyPrintMultipleErrors (P.optionsVerboseErrors opts) errs)
93 exitFailure
92 exitFailure
94− Right _ -> do
93+ Right (_, warnings) -> do
94+ when (P.nonEmpty warnings) $
95+ putStrLn (P.prettyPrintMultipleWarnings (P.optionsVerboseErrors opts) warnings)
95 exitSuccess
96 exitSuccess
96 where
97 where
97 prefix = if usePrefix
98 prefix = if usePrefix
@@ -122,7 +123,7 @@ noTco = switch $
122noPrelude :: Parser Bool
123noPrelude :: Parser Bool
123noPrelude = switch $
124noPrelude = switch $
124 long "no-prelude"
125 long "no-prelude"
125− <> help "Omit the Prelude"
126+ <> help "Omit the automatic Prelude import"
126
127
127noMagicDo :: Parser Bool
128noMagicDo :: Parser Bool
128noMagicDo = switch $
129noMagicDo = switch $
psc/Main.hs+12−6
@@ -19,6 +19,7 @@ module Main where
19import Control.Applicative
19import Control.Applicative
20import Control.Monad
20import Control.Monad
21import Control.Monad.Reader
21import Control.Monad.Reader
22+import Control.Monad.Writer
22
23
23import Data.Maybe (fromMaybe)
24import Data.Maybe (fromMaybe)
24import Data.Version (showVersion)
25import Data.Version (showVersion)
@@ -32,7 +33,6 @@ import System.IO (hPutStrLn, stderr)
32import qualified Language.PureScript as P
33import qualified Language.PureScript as P
33import qualified Paths_purescript as Paths
34import qualified Paths_purescript as Paths
34
35
35−
36data PSCOptions = PSCOptions
36data PSCOptions = PSCOptions
37 { pscInput :: [FilePath]
37 { pscInput :: [FilePath]
38 , pscOpts :: P.Options P.Compile
38 , pscOpts :: P.Options P.Compile
@@ -51,8 +51,12 @@ data InputOptions = InputOptions
51readInput :: InputOptions -> IO [(Maybe FilePath, String)]
51readInput :: InputOptions -> IO [(Maybe FilePath, String)]
52readInput InputOptions{..}
52readInput InputOptions{..}
53 | ioUseStdIn = return . (Nothing ,) <$> getContents
53 | ioUseStdIn = return . (Nothing ,) <$> getContents
54− | otherwise = do content <- forM ioInputFiles $ \inFile -> (Just inFile, ) <$> readFile inFile
54+ | otherwise = forM ioInputFiles $ \inFile -> (Just inFile, ) <$> readFile inFile
55− return (if ioNoPrelude then content else (Nothing, P.prelude) : content)
55+
56+type PSC = ReaderT (P.Options P.Compile) (WriterT P.MultipleErrors (Either P.MultipleErrors))
57+
58+runPSC :: P.Options P.Compile -> PSC a -> Either P.MultipleErrors (a, P.MultipleErrors)
59+runPSC opts rwe = runWriterT (runReaderT rwe opts)
56
60
57compile :: PSCOptions -> IO ()
61compile :: PSCOptions -> IO ()
58compile (PSCOptions input opts stdin output externs usePrefix) = do
62compile (PSCOptions input opts stdin output externs usePrefix) = do
@@ -62,11 +66,13 @@ compile (PSCOptions input opts stdin output externs usePrefix) = do
62 hPutStrLn stderr $ show err
66 hPutStrLn stderr $ show err
63 exitFailure
67 exitFailure
64 Right ms -> do
68 Right ms -> do
65− case P.compile (map snd ms) prefix `runReaderT` opts of
69+ case runPSC opts (P.compile (map snd ms) prefix) of
66 Left errs -> do
70 Left errs -> do
67 hPutStrLn stderr (P.prettyPrintMultipleErrors (P.optionsVerboseErrors opts) errs)
71 hPutStrLn stderr (P.prettyPrintMultipleErrors (P.optionsVerboseErrors opts) errs)
68 exitFailure
72 exitFailure
69− Right (js, exts, _) -> do
73+ Right ((js, exts, _), warnings) -> do
74+ when (P.nonEmpty warnings) $
75+ hPutStrLn stderr (P.prettyPrintMultipleWarnings (P.optionsVerboseErrors opts) warnings)
70 case output of
76 case output of
71 Just path -> mkdirp path >> writeFile path js
77 Just path -> mkdirp path >> writeFile path js
72 Nothing -> putStrLn js
78 Nothing -> putStrLn js
@@ -136,7 +142,7 @@ noTco = switch $
136noPrelude :: Parser Bool
142noPrelude :: Parser Bool
137noPrelude = switch $
143noPrelude = switch $
138 long "no-prelude"
144 long "no-prelude"
139− <> help "Omit the Prelude"
145+ <> help "Omit the automatic Prelude import"
140
146
141comments :: Parser Bool
147comments :: Parser Bool
142comments = switch $
148comments = switch $
psci/PSCi.hs+5−4
@@ -33,6 +33,7 @@ import Control.Monad.IO.Class (MonadIO, liftIO)
33import Control.Monad.Error.Class (MonadError(..))
33import Control.Monad.Error.Class (MonadError(..))
34import Control.Monad.Trans.Except (ExceptT(..), runExceptT)
34import Control.Monad.Trans.Except (ExceptT(..), runExceptT)
35import Control.Monad.Reader (MonadReader, ReaderT, runReaderT)
35import Control.Monad.Reader (MonadReader, ReaderT, runReaderT)
36+import Control.Monad.Writer (MonadWriter, WriterT, runWriterT)
36import Control.Monad.Trans.Class
37import Control.Monad.Trans.Class
37import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
38import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
38import Control.Monad.Trans.State.Strict
39import Control.Monad.Trans.State.Strict
@@ -100,7 +101,7 @@ loadAllModules files = do
100 filesAndContent <- forM files $ \filename -> do
101 filesAndContent <- forM files $ \filename -> do
101 content <- readFile filename
102 content <- readFile filename
102 return (Right filename, content)
103 return (Right filename, content)
103− return $ P.parseModulesFromFiles (either (const "") id) $ (Left P.RebuildNever, P.prelude) : filesAndContent
104+ return $ P.parseModulesFromFiles (either (const "") id) filesAndContent
104
105
105-- |
106-- |
106-- Load all modules, updating the application state
107-- Load all modules, updating the application state
@@ -182,11 +183,11 @@ newtype PSCI a = PSCI { runPSCI :: InputT (StateT PSCiState IO) a } deriving (Fu
182psciIO :: IO a -> PSCI a
183psciIO :: IO a -> PSCI a
183psciIO io = PSCI . lift $ lift io
184psciIO io = PSCI . lift $ lift io
184
185
185−newtype Make a = Make { unMake :: ReaderT (P.Options P.Make) (ExceptT P.MultipleErrors IO) a }
186+newtype Make a = Make { unMake :: ReaderT (P.Options P.Make) (WriterT P.MultipleErrors (ExceptT P.MultipleErrors IO)) a }
186− deriving (Functor, Applicative, Monad, MonadIO, MonadError P.MultipleErrors, MonadReader (P.Options P.Make))
187+ deriving (Functor, Applicative, Monad, MonadIO, MonadError P.MultipleErrors, MonadWriter P.MultipleErrors, MonadReader (P.Options P.Make))
187
188
188runMake :: Make a -> IO (Either P.MultipleErrors a)
189runMake :: Make a -> IO (Either P.MultipleErrors a)
189−runMake = runExceptT . flip runReaderT options . unMake
190+runMake = runExceptT . fmap fst . runWriterT . flip runReaderT options . unMake
190
191
191makeIO :: (IOError -> P.ErrorMessage) -> IO a -> Make a
192makeIO :: (IOError -> P.ErrorMessage) -> IO a -> Make a
192makeIO f io = do
193makeIO f io = do
purescript.cabal+2−2
@@ -1,5 +1,5 @@
1name: purescript
1name: purescript
2−version: 0.6.9.4
2+version: 0.7.0.0
3cabal-version: >=1.8
3cabal-version: >=1.8
4build-type: Simple
4build-type: Simple
5license: MIT
5license: MIT
@@ -35,7 +35,6 @@ library
35 transformers-compat >= 0.3.0,
35 transformers-compat >= 0.3.0,
36 utf8-string >= 1 && < 2,
36 utf8-string >= 1 && < 2,
37 pattern-arrows >= 0.0.2 && < 0.1,
37 pattern-arrows >= 0.0.2 && < 0.1,
38− file-embed >= 0.0.7 && < 0.0.8,
39 time -any,
38 time -any,
40 boxes >= 0.1.4 && < 0.2.0
39 boxes >= 0.1.4 && < 0.2.0
41 exposed-modules: Language.PureScript
40 exposed-modules: Language.PureScript
@@ -72,6 +71,7 @@ library
72 Language.PureScript.Environment
71 Language.PureScript.Environment
73 Language.PureScript.Errors
72 Language.PureScript.Errors
74 Language.PureScript.Kinds
73 Language.PureScript.Kinds
74+ Language.PureScript.Linter
75 Language.PureScript.ModuleDependencies
75 Language.PureScript.ModuleDependencies
76 Language.PureScript.Names
76 Language.PureScript.Names
77 Language.PureScript.Options
77 Language.PureScript.Options
src/Language/PureScript.hs+27−17
@@ -26,18 +26,15 @@ module Language.PureScript
26 , RebuildPolicy(..)
26 , RebuildPolicy(..)
27 , MonadMake(..)
27 , MonadMake(..)
28 , make
28 , make
29− , prelude
30 , version
29 , version
31 ) where
30 ) where
32
31
33−import Data.FileEmbed (embedFile)
34import Data.Function (on)
32import Data.Function (on)
35import Data.List (sortBy, groupBy, intercalate)
33import Data.List (sortBy, groupBy, intercalate)
36import Data.Maybe (fromMaybe)
34import Data.Maybe (fromMaybe)
37import Data.Time.Clock
35import Data.Time.Clock
38import Data.Version (Version)
36import Data.Version (Version)
39import qualified Data.Traversable as T (traverse)
37import qualified Data.Traversable as T (traverse)
40−import qualified Data.ByteString.UTF8 as BU
41import qualified Data.Map as M
38import qualified Data.Map as M
42import qualified Data.Set as S
39import qualified Data.Set as S
43
40
@@ -46,6 +43,7 @@ import Control.Arrow ((&&&))
46import Control.Monad
43import Control.Monad
47import Control.Monad.Error.Class (MonadError(..))
44import Control.Monad.Error.Class (MonadError(..))
48import Control.Monad.Reader
45import Control.Monad.Reader
46+import Control.Monad.Writer
49
47
50import System.FilePath ((</>))
48import System.FilePath ((</>))
51
49
@@ -56,6 +54,7 @@ import Language.PureScript.DeadCodeElimination as P
56import Language.PureScript.Environment as P
54import Language.PureScript.Environment as P
57import Language.PureScript.Errors as P
55import Language.PureScript.Errors as P
58import Language.PureScript.Kinds as P
56import Language.PureScript.Kinds as P
57+import Language.PureScript.Linter as P
59import Language.PureScript.ModuleDependencies as P
58import Language.PureScript.ModuleDependencies as P
60import Language.PureScript.Names as P
59import Language.PureScript.Names as P
61import Language.PureScript.Options as P
60import Language.PureScript.Options as P
@@ -90,26 +89,28 @@ import qualified Paths_purescript as Paths
90--
89--
91-- * Pretty-print the generated Javascript
90-- * Pretty-print the generated Javascript
92--
91--
93−compile :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadReader (Options Compile) m)
92+compile :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m, MonadReader (Options Compile) m)
94 => [Module] -> [String] -> m (String, String, Environment)
93 => [Module] -> [String] -> m (String, String, Environment)
95compile = compile' initEnvironment
94compile = compile' initEnvironment
96
95
97−compile' :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadReader (Options Compile) m)
96+compile' :: (Functor m, Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m, MonadReader (Options Compile) m)
98 => Environment -> [Module] -> [String] -> m (String, String, Environment)
97 => Environment -> [Module] -> [String] -> m (String, String, Environment)
99compile' env ms prefix = do
98compile' env ms prefix = do
100 noPrelude <- asks optionsNoPrelude
99 noPrelude <- asks optionsNoPrelude
100+ unless noPrelude (checkPreludeIsDefined ms)
101 additional <- asks optionsAdditional
101 additional <- asks optionsAdditional
102 mainModuleIdent <- asks (fmap moduleNameFromString . optionsMain)
102 mainModuleIdent <- asks (fmap moduleNameFromString . optionsMain)
103 (sorted, _) <- sortModules $ map importPrim $ if noPrelude then ms else map importPrelude ms
103 (sorted, _) <- sortModules $ map importPrim $ if noPrelude then ms else map importPrelude ms
104+ mapM_ lint sorted
104 (desugared, nextVar) <- runSupplyT 0 $ desugar sorted
105 (desugared, nextVar) <- runSupplyT 0 $ desugar sorted
105 (elaborated, env') <- runCheck' env $ forM desugared $ typeCheckModule mainModuleIdent
106 (elaborated, env') <- runCheck' env $ forM desugared $ typeCheckModule mainModuleIdent
106 regrouped <- createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
107 regrouped <- createBindingGroupsModule . collapseBindingGroupsModule $ elaborated
107 let corefn = map (CoreFn.moduleToCoreFn env') regrouped
108 let corefn = map (CoreFn.moduleToCoreFn env') regrouped
108− let entryPoints = moduleNameFromString `map` entryPointModules additional
109+ entryPoints = moduleNameFromString `map` entryPointModules additional
109− let elim = if null entryPoints then corefn else eliminateDeadCode entryPoints corefn
110+ elim = if null entryPoints then corefn else eliminateDeadCode entryPoints corefn
110− let renamed = renameInModules elim
111+ renamed = renameInModules elim
111− let codeGenModuleNames = moduleNameFromString `map` codeGenModules additional
112+ codeGenModuleNames = moduleNameFromString `map` codeGenModules additional
112− let modulesToCodeGen = if null codeGenModuleNames then renamed else filter (\(CoreFn.Module _ mn _ _ _ _) -> mn `elem` codeGenModuleNames) renamed
113+ modulesToCodeGen = if null codeGenModuleNames then renamed else filter (\(CoreFn.Module _ mn _ _ _ _) -> mn `elem` codeGenModuleNames) renamed
113 js <- concat <$> (evalSupplyT nextVar $ T.traverse moduleToJs modulesToCodeGen)
114 js <- concat <$> (evalSupplyT nextVar $ T.traverse moduleToJs modulesToCodeGen)
114 let exts = intercalate "\n" . map (`moduleToPs` env') $ regrouped
115 let exts = intercalate "\n" . map (`moduleToPs` env') $ regrouped
115 js' <- generateMain env' js
116 js' <- generateMain env' js
@@ -130,7 +131,7 @@ generateMain env js = do
130-- |
131-- |
131-- A type class which collects the IO actions we need to be able to run in "make" mode
132-- A type class which collects the IO actions we need to be able to run in "make" mode
132--
133--
133−class (MonadReader (P.Options P.Make) m, MonadError MultipleErrors m) => MonadMake m where
134+class (MonadReader (P.Options P.Make) m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) => MonadMake m where
134 -- |
135 -- |
135 -- Get a file timestamp
136 -- Get a file timestamp
136 --
137 --
@@ -175,10 +176,13 @@ make :: forall m. (Functor m, Applicative m, Monad m, MonadMake m)
175 => FilePath -> [(Either RebuildPolicy FilePath, Module)] -> [String] -> m Environment
176 => FilePath -> [(Either RebuildPolicy FilePath, Module)] -> [String] -> m Environment
176make outputDir ms prefix = do
177make outputDir ms prefix = do
177 noPrelude <- asks optionsNoPrelude
178 noPrelude <- asks optionsNoPrelude
179+ unless noPrelude (checkPreludeIsDefined (map snd ms))
178 let filePathMap = M.fromList (map (\(fp, Module _ mn _ _) -> (mn, fp)) ms)
180 let filePathMap = M.fromList (map (\(fp, Module _ mn _ _) -> (mn, fp)) ms)
179
181
180 (sorted, graph) <- sortModules $ map importPrim $ if noPrelude then map snd ms else map (importPrelude . snd) ms
182 (sorted, graph) <- sortModules $ map importPrim $ if noPrelude then map snd ms else map (importPrelude . snd) ms
181
183
184+ mapM_ lint sorted
185+
182 toRebuild <- foldM (\s (Module _ moduleName' _ _) -> do
186 toRebuild <- foldM (\s (Module _ moduleName' _ _) -> do
183 let filePath = runModuleName moduleName'
187 let filePath = runModuleName moduleName'
184
188
@@ -220,8 +224,8 @@ make outputDir ms prefix = do
220 regrouped <- createBindingGroups moduleName' . collapseBindingGroups $ elaborated
224 regrouped <- createBindingGroups moduleName' . collapseBindingGroups $ elaborated
221
225
222 let mod' = Module coms moduleName' regrouped exps
226 let mod' = Module coms moduleName' regrouped exps
223− let corefn = CoreFn.moduleToCoreFn env' mod'
227+ corefn = CoreFn.moduleToCoreFn env' mod'
224− let [renamed] = renameInModules [corefn]
228+ [renamed] = renameInModules [corefn]
225
229
226 pjs <- prettyPrintJS <$> moduleToJs renamed
230 pjs <- prettyPrintJS <$> moduleToJs renamed
227 let js = unlines $ map ("// " ++) prefix ++ [pjs]
231 let js = unlines $ map ("// " ++) prefix ++ [pjs]
@@ -246,6 +250,12 @@ make outputDir ms prefix = do
246 [m'@(Module _ moduleName'' _ _)] | moduleName'' == moduleName' -> (:) (False, m') <$> rebuildIfNecessary graph toRebuild ms'
250 [m'@(Module _ moduleName'' _ _)] | moduleName'' == moduleName' -> (:) (False, m') <$> rebuildIfNecessary graph toRebuild ms'
247 _ -> throwError . errorMessage . InvalidExternsFile $ externsFile
251 _ -> throwError . errorMessage . InvalidExternsFile $ externsFile
248
252
253+checkPreludeIsDefined :: (MonadWriter MultipleErrors m) => [Module] -> m ()
254+checkPreludeIsDefined ms = do
255+ let mns = map getModuleName ms
256+ unless (preludeModuleName `elem` mns) $
257+ tell (errorMessage PreludeNotPresent)
258+
249reverseDependencies :: ModuleGraph -> M.Map ModuleName [ModuleName]
259reverseDependencies :: ModuleGraph -> M.Map ModuleName [ModuleName]
250reverseDependencies g = combine [ (dep, mn) | (mn, deps) <- g, dep <- deps ]
260reverseDependencies g = combine [ (dep, mn) | (mn, deps) <- g, dep <- deps ]
251 where
261 where
@@ -267,11 +277,11 @@ addDefaultImport toImport m@(Module coms mn decls exps) =
267importPrim :: Module -> Module
277importPrim :: Module -> Module
268importPrim = addDefaultImport (ModuleName [ProperName C.prim])
278importPrim = addDefaultImport (ModuleName [ProperName C.prim])
269
279
270−importPrelude :: Module -> Module
280+preludeModuleName :: ModuleName
271−importPrelude = addDefaultImport (ModuleName [ProperName C.prelude])
281+preludeModuleName = ModuleName [ProperName C.prelude]
272
282
273−prelude :: String
283+importPrelude :: Module -> Module
274−prelude = BU.toString $(embedFile "prelude/prelude.purs")
284+importPrelude = addDefaultImport preludeModuleName
275
285
276version :: Version
286version :: Version
277version = Paths.version
287version = Paths.version
src/Language/PureScript/Errors.hs+27−4
@@ -108,6 +108,8 @@ data ErrorMessage
108 | InvalidNewtype
108 | InvalidNewtype
109 | InvalidInstanceHead Type
109 | InvalidInstanceHead Type
110 | TransitiveExportError DeclarationRef [DeclarationRef]
110 | TransitiveExportError DeclarationRef [DeclarationRef]
111+ | ShadowedName Ident
112+ | PreludeNotPresent
111 | ErrorInExpression Expr ErrorMessage
113 | ErrorInExpression Expr ErrorMessage
112 | ErrorInModule ModuleName ErrorMessage
114 | ErrorInModule ModuleName ErrorMessage
113 | ErrorInInstance (Qualified ProperName) [Type] ErrorMessage
115 | ErrorInInstance (Qualified ProperName) [Type] ErrorMessage
@@ -199,6 +201,8 @@ errorCode TypeSynonymInstance = "TypeSynonymInstance"
199errorCode InvalidNewtype = "InvalidNewtype"
201errorCode InvalidNewtype = "InvalidNewtype"
200errorCode (InvalidInstanceHead _) = "InvalidInstanceHead"
202errorCode (InvalidInstanceHead _) = "InvalidInstanceHead"
201errorCode (TransitiveExportError _ _) = "TransitiveExportError"
203errorCode (TransitiveExportError _ _) = "TransitiveExportError"
204+errorCode (ShadowedName _) = "ShadowedName"
205+errorCode PreludeNotPresent = "PreludeNotPresent"
202errorCode (NotYetDefined _ e) = errorCode e
206errorCode (NotYetDefined _ e) = errorCode e
203errorCode (ErrorUnifyingTypes _ _ e) = errorCode e
207errorCode (ErrorUnifyingTypes _ _ e) = errorCode e
204errorCode (ErrorInExpression _ e) = errorCode e
208errorCode (ErrorInExpression _ e) = errorCode e
@@ -230,6 +234,10 @@ instance UnificationError Type MultipleErrors where
230instance UnificationError Kind MultipleErrors where
234instance UnificationError Kind MultipleErrors where
231 occursCheckFailed = errorMessage . occursCheckFailed
235 occursCheckFailed = errorMessage . occursCheckFailed
232
236
237+-- | Check whether a collection of errors is empty or not.
238+nonEmpty :: MultipleErrors -> Bool
239+nonEmpty = not . null . runMultipleErrors
240+
233-- |
241-- |
234-- Create an error set from a single error message
242-- Create an error set from a single error message
235--
243--
@@ -375,6 +383,10 @@ prettyPrintSingleError full e = prettyPrintErrorMessage (if full then e else sim
375 ]
383 ]
376 go (TransitiveExportError x ys) = paras $ (line $ "An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
384 go (TransitiveExportError x ys) = paras $ (line $ "An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
377 : map (line . prettyPrintExport) ys
385 : map (line . prettyPrintExport) ys
386+ go (ShadowedName nm) = line $ "Name '" ++ show nm ++ "' was shadowed."
387+ go PreludeNotPresent = paras [ line $ "There is no Prelude module loaded, and the --no-prelude option was not specified."
388+ , line $ "You probably need to install the Prelude and other dependencies using Bower."
389+ ]
378 go (ErrorUnifyingTypes t1 t2 err) = paras [ line "Error unifying type "
390 go (ErrorUnifyingTypes t1 t2 err) = paras [ line "Error unifying type "
379 , indent $ line $ prettyPrintType t1
391 , indent $ line $ prettyPrintType t1
380 , line "with type"
392 , line "with type"
@@ -511,10 +523,21 @@ prettyPrintSingleError full e = prettyPrintErrorMessage (if full then e else sim
511-- Pretty print multiple errors
523-- Pretty print multiple errors
512--
524--
513prettyPrintMultipleErrors :: Bool -> MultipleErrors -> String
525prettyPrintMultipleErrors :: Bool -> MultipleErrors -> String
526+prettyPrintMultipleErrors = prettyPrintMultipleErrorsWith "Error:" "Multiple errors:"
527+
528+-- |
529+-- Pretty print multiple warnings
530+--
531+prettyPrintMultipleWarnings :: Bool -> MultipleErrors -> String
532+prettyPrintMultipleWarnings = prettyPrintMultipleErrorsWith "Warning:" "Multiple warnings:"
533+
534+prettyPrintMultipleErrorsWith :: String -> String -> Bool -> MultipleErrors -> String
514−prettyPrintMultipleErrors full (MultipleErrors [e]) = renderBox $
535+prettyPrintMultipleErrorsWith intro _ full (MultipleErrors [e]) = renderBox $
536+ Box.vcat Box.left [ Box.text intro
515− prettyPrintSingleError full e
537+ , prettyPrintSingleError full e
538+ ]
516−prettyPrintMultipleErrors full (MultipleErrors es) = renderBox $
539+prettyPrintMultipleErrorsWith _ intro full (MultipleErrors es) = renderBox $
517− Box.vcat Box.left [ Box.text "Multiple errors:"
540+ Box.vcat Box.left [ Box.text intro
518 , Box.vsep 1 Box.left $ map (Box.moveRight 2 . prettyPrintSingleError full) es
541 , Box.vsep 1 Box.left $ map (Box.moveRight 2 . prettyPrintSingleError full) es
519 ]
542 ]
520
543
src/Language/PureScript/Linter.hsnew file+73
@@ -0,0 +1,73 @@
1+-----------------------------------------------------------------------------
2+--
3+-- Module : Language.PureScript.Linter
4+-- Copyright : (c) Copyright 2015 PureScript
5+-- License : MIT
6+--
7+-- Maintainer : Phil Freeman <paf31@cantab.net>
8+-- Stability : experimental
9+-- Portability :
10+--
11+-- | This module implements a simple linting pass on the PureScript AST.
12+--
13+-----------------------------------------------------------------------------
14+
15+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
16+{-# LANGUAGE FlexibleContexts #-}
17+{-# LANGUAGE ScopedTypeVariables #-}
18+
19+module Language.PureScript.Linter (lint) where
20+
21+import Data.List (mapAccumL, nub)
22+import Data.Maybe (mapMaybe)
23+import Data.Monoid
24+
25+import qualified Data.Set as S
26+
27+import Control.Applicative
28+import Control.Monad.Writer.Class
29+
30+import Language.PureScript.AST
31+import Language.PureScript.Names
32+import Language.PureScript.Errors
33+
34+-- | Lint the PureScript AST.
35+-- |
36+-- | Right now, this pass only performs a shadowing check.
37+lint :: forall m. (Applicative m, MonadWriter MultipleErrors m) => Module -> m ()
38+lint (Module _ mn ds _) = censor (onErrorMessages (ErrorInModule mn)) $ mapM_ lintDeclaration ds
39+ where
40+ moduleNames :: S.Set Ident
41+ moduleNames = S.fromList (nub (mapMaybe getDeclIdent ds))
42+
43+ getDeclIdent :: Declaration -> Maybe Ident
44+ getDeclIdent (PositionedDeclaration _ _ d) = getDeclIdent d
45+ getDeclIdent (ValueDeclaration ident _ _ _) = Just ident
46+ getDeclIdent (ExternDeclaration _ ident _ _) = Just ident
47+ getDeclIdent (ExternInstanceDeclaration ident _ _ _) = Just ident
48+ getDeclIdent (TypeInstanceDeclaration ident _ _ _ _) = Just ident
49+ getDeclIdent (BindingGroupDeclaration _) = error "lint: binding groups should not be desugared yet."
50+ getDeclIdent _ = Nothing
51+
52+ lintDeclaration :: Declaration -> m ()
53+ lintDeclaration d =
54+ let (f, _, _, _, _) = everythingWithContextOnValues moduleNames mempty mappend def stepE stepB def def
55+ in tell (f d)
56+ where
57+ def s _ = (s, mempty)
58+
59+ stepE :: S.Set Ident -> Expr -> (S.Set Ident, MultipleErrors)
60+ stepE s (Abs (Left name) _) = bind s name
61+ stepE s (Let ds' _) =
62+ case mapAccumL bind s (nub (mapMaybe getDeclIdent ds')) of
63+ (s', es) -> (s', mconcat es)
64+ stepE s _ = (s, mempty)
65+
66+ stepB :: S.Set Ident -> Binder -> (S.Set Ident, MultipleErrors)
67+ stepB s (VarBinder name) = bind s name
68+ stepB s (NamedBinder name _) = bind s name
69+ stepB s _ = (s, mempty)
70+
71+ bind :: S.Set Ident -> Ident -> (S.Set Ident, MultipleErrors)
72+ bind s name | name `S.member` s = (s, errorMessage (ShadowedName name))
73+ | otherwise = (S.insert name s, mempty)
src/Language/PureScript/Renamer.hs+11−9
@@ -14,6 +14,8 @@
14--
14--
15-----------------------------------------------------------------------------
15-----------------------------------------------------------------------------
16
16
17+{-# LANGUAGE FlexibleContexts, ScopedTypeVariables #-}
18+
17module Language.PureScript.Renamer (renameInModules) where
19module Language.PureScript.Renamer (renameInModules) where
18
20
19import Control.Applicative
21import Control.Applicative
@@ -74,13 +76,12 @@ updateScope :: Ident -> Rename Ident
74updateScope i@(Ident name) | name == C.__unused = return i
76updateScope i@(Ident name) | name == C.__unused = return i
75updateScope name = do
77updateScope name = do
76 scope <- get
78 scope <- get
77− let name' = case name `S.member` rsUsedNames scope of
79+ name' <- case name `S.member` rsUsedNames scope of
78− True ->
80+ True -> do
79− let
80− newNames = [ Ident (runIdent name ++ "_" ++ show (i :: Int)) | i <- [1..] ]
81+ let newNames = [ Ident (runIdent name ++ "_" ++ show (i :: Int)) | i <- [1..] ]
81− Just newName = find (`S.notMember` rsUsedNames scope) newNames
82+ Just newName = find (`S.notMember` rsUsedNames scope) newNames
82− in newName
83+ return newName
83− False -> name
84+ False -> return name
84 modify $ \s -> s { rsBoundNames = M.insert name name' (rsBoundNames s)
85 modify $ \s -> s { rsBoundNames = M.insert name name' (rsBoundNames s)
85 , rsUsedNames = S.insert name' (rsUsedNames s)
86 , rsUsedNames = S.insert name' (rsUsedNames s)
86 }
87 }
@@ -113,7 +114,8 @@ renameInModules :: [Module Ann] -> [Module Ann]
113renameInModules = map go
114renameInModules = map go
114 where
115 where
115 go :: Module Ann -> Module Ann
116 go :: Module Ann -> Module Ann
116− go m@(Module _ _ _ _ _ decls) = m { moduleDecls = renameInDecl' (findDeclIdents decls) `map` decls }
117+ go m@(Module _ _ _ _ _ decls) = m { moduleDecls = map (renameInDecl' (findDeclIdents decls)) decls }
118+
117 renameInDecl' :: [Ident] -> Bind Ann -> Bind Ann
119 renameInDecl' :: [Ident] -> Bind Ann -> Bind Ann
118 renameInDecl' scope = runRename scope . renameInDecl True
120 renameInDecl' scope = runRename scope . renameInDecl True
119
121
@@ -175,7 +177,7 @@ renameInLiteral _ l = return l
175-- Renames within case alternatives.
177-- Renames within case alternatives.
176--
178--
177renameInCaseAlternative :: CaseAlternative Ann -> Rename (CaseAlternative Ann)
179renameInCaseAlternative :: CaseAlternative Ann -> Rename (CaseAlternative Ann)
178−renameInCaseAlternative (CaseAlternative bs v) =
180+renameInCaseAlternative (CaseAlternative bs v) = newScope $
179 CaseAlternative <$> mapM renameInBinder bs
181 CaseAlternative <$> mapM renameInBinder bs
180 <*> eitherM (mapM (pairM renameInValue renameInValue)) renameInValue v
182 <*> eitherM (mapM (pairM renameInValue renameInValue)) renameInValue v
181
183
src/Language/PureScript/Sugar/CaseDeclarations.hs+19−11
@@ -14,7 +14,7 @@
14--
14--
15-----------------------------------------------------------------------------
15-----------------------------------------------------------------------------
16
16
17−{-# LANGUAGE FlexibleContexts #-}
17+{-# LANGUAGE FlexibleContexts, ScopedTypeVariables #-}
18
18
19module Language.PureScript.Sugar.CaseDeclarations (
19module Language.PureScript.Sugar.CaseDeclarations (
20 desugarCases,
20 desugarCases,
@@ -89,12 +89,24 @@ inSameGroup (PositionedDeclaration _ _ d1) d2 = inSameGroup d1 d2
89inSameGroup d1 (PositionedDeclaration _ _ d2) = inSameGroup d1 d2
89inSameGroup d1 (PositionedDeclaration _ _ d2) = inSameGroup d1 d2
90inSameGroup _ _ = False
90inSameGroup _ _ = False
91
91
92−toDecls :: (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m) => [Declaration] -> m [Declaration]
92+toDecls :: forall m. (Functor m, Applicative m, Monad m, MonadSupply m, MonadError MultipleErrors m) => [Declaration] -> m [Declaration]
93toDecls [ValueDeclaration ident nameKind bs (Right val)] | all isVarBinder bs = do
93toDecls [ValueDeclaration ident nameKind bs (Right val)] | all isVarBinder bs = do
94− let args = map (\(VarBinder arg) -> arg) bs
94+ args <- mapM fromVarBinder bs
95− body = foldr (Abs . Left) val args
95+ let body = foldr (Abs . Left) val args
96 guardWith (errorMessage (OverlappingArgNames (Just ident))) $ length (nub args) == length args
96 guardWith (errorMessage (OverlappingArgNames (Just ident))) $ length (nub args) == length args
97 return [ValueDeclaration ident nameKind [] (Right body)]
97 return [ValueDeclaration ident nameKind [] (Right body)]
98+ where
99+ isVarBinder :: Binder -> Bool
100+ isVarBinder NullBinder = True
101+ isVarBinder (VarBinder _) = True
102+ isVarBinder (PositionedBinder _ _ b) = isVarBinder b
103+ isVarBinder _ = False
104+
105+ fromVarBinder :: Binder -> m Ident
106+ fromVarBinder NullBinder = Ident <$> freshName
107+ fromVarBinder (VarBinder name) = return name
108+ fromVarBinder (PositionedBinder _ _ b) = fromVarBinder b
109+ fromVarBinder _ = error "fromVarBinder: Invalid argument"
98toDecls ds@(ValueDeclaration ident _ bs result : _) = do
110toDecls ds@(ValueDeclaration ident _ bs result : _) = do
99 let tuples = map toTuple ds
111 let tuples = map toTuple ds
100 unless (all ((== length bs) . length . fst) tuples) $
112 unless (all ((== length bs) . length . fst) tuples) $
@@ -108,16 +120,12 @@ toDecls (PositionedDeclaration pos com d : ds) = do
108 return (PositionedDeclaration pos com d' : ds')
120 return (PositionedDeclaration pos com d' : ds')
109toDecls ds = return ds
121toDecls ds = return ds
110
122
111−isVarBinder :: Binder -> Bool
112−isVarBinder (VarBinder _) = True
113−isVarBinder _ = False
114−
115toTuple :: Declaration -> ([Binder], Either [(Guard, Expr)] Expr)
123toTuple :: Declaration -> ([Binder], Either [(Guard, Expr)] Expr)
116toTuple (ValueDeclaration _ _ bs result) = (bs, result)
124toTuple (ValueDeclaration _ _ bs result) = (bs, result)
117toTuple (PositionedDeclaration _ _ d) = toTuple d
125toTuple (PositionedDeclaration _ _ d) = toTuple d
118toTuple _ = error "Not a value declaration"
126toTuple _ = error "Not a value declaration"
119
127
120−makeCaseDeclaration :: (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m) => Ident -> [([Binder], Either [(Guard, Expr)] Expr)] -> m Declaration
128+makeCaseDeclaration :: forall m. (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m) => Ident -> [([Binder], Either [(Guard, Expr)] Expr)] -> m Declaration
121makeCaseDeclaration ident alternatives = do
129makeCaseDeclaration ident alternatives = do
122 let namedArgs = map findName . fst <$> alternatives
130 let namedArgs = map findName . fst <$> alternatives
123 argNames = map join $ foldl1 resolveNames namedArgs
131 argNames = map join $ foldl1 resolveNames namedArgs
@@ -134,7 +142,7 @@ makeCaseDeclaration ident alternatives = do
134 -- NullBinder will become Just Nothing, which indicates that we may
142 -- NullBinder will become Just Nothing, which indicates that we may
135 -- have to generate a name.
143 -- have to generate a name.
136 -- Everything else becomes Nothing, which indicates that we definitely
144 -- Everything else becomes Nothing, which indicates that we definitely
137− --have to generate a name.
145+ -- have to generate a name.
138 findName :: Binder -> Maybe (Maybe Ident)
146 findName :: Binder -> Maybe (Maybe Ident)
139 findName NullBinder = Just Nothing
147 findName NullBinder = Just Nothing
140 findName (VarBinder name) = Just (Just name)
148 findName (VarBinder name) = Just (Just name)
@@ -146,7 +154,7 @@ makeCaseDeclaration ident alternatives = do
146 allUnique :: (Eq a) => [a] -> Bool
154 allUnique :: (Eq a) => [a] -> Bool
147 allUnique xs = length xs == length (nub xs)
155 allUnique xs = length xs == length (nub xs)
148
156
149− argName :: (MonadSupply m) => Maybe Ident -> m Ident
157+ argName :: Maybe Ident -> m Ident
150 argName (Just name) = return name
158 argName (Just name) = return name
151 argName _ = do
159 argName _ = do
152 name <- freshName
160 name <- freshName
src/Language/PureScript/TypeChecker/Entailment.hs+43−27
@@ -13,6 +13,8 @@
13--
13--
14-----------------------------------------------------------------------------
14-----------------------------------------------------------------------------
15
15
16+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
17+
16module Language.PureScript.TypeChecker.Entailment (
18module Language.PureScript.TypeChecker.Entailment (
17 entails
19 entails
18) where
20) where
@@ -25,7 +27,7 @@ import qualified Data.Map as M
25
27
26import Control.Applicative
28import Control.Applicative
27import Control.Arrow (Arrow(..))
29import Control.Arrow (Arrow(..))
28−import Control.Monad
30+import Control.Monad.State
29import Control.Monad.Error.Class (MonadError(..))
31import Control.Monad.Error.Class (MonadError(..))
30
32
31import Language.PureScript.AST
33import Language.PureScript.AST
@@ -39,6 +41,8 @@ import Language.PureScript.TypeClassDictionaries
39import Language.PureScript.Types
41import Language.PureScript.Types
40import qualified Language.PureScript.Constants as C
42import qualified Language.PureScript.Constants as C
41
43
44+newtype Work = Work Integer deriving (Show, Eq, Ord, Num)
45+
42-- |
46-- |
43-- Check that the current set of type class dictionaries entail the specified type class goal, and, if so,
47-- Check that the current set of type class dictionaries entail the specified type class goal, and, if so,
44-- return a type class dictionary reference.
48-- return a type class dictionary reference.
@@ -55,47 +59,59 @@ entails env moduleName context = solve (sortedNubBy canonicalizeDictionary (filt
55 filterModule (TypeClassDictionaryInScope { tcdName = Qualified Nothing _ }) = True
59 filterModule (TypeClassDictionaryInScope { tcdName = Qualified Nothing _ }) = True
56 filterModule _ = False
60 filterModule _ = False
57
61
62+ solve :: [TypeClassDictionaryInScope] -> Constraint -> Bool -> Check Expr
58− solve context' (className, tys) trySuperclasses =
63+ solve context' (className, tys) trySuperclasses = do
59− checkOverlaps $ go trySuperclasses className tys
64+ let dicts = flip evalStateT (Work 0) $ go trySuperclasses className tys
65+ checkOverlaps dicts
60 where
66 where
67+ go :: Bool -> Qualified ProperName -> [Type] -> StateT Work [] DictionaryValue
61− go trySuperclasses' className' tys' =
68+ go trySuperclasses' className' tys' = do
62− -- Look for regular type instances
69+ workDone <- get
63− [ mkDictionary (canonicalizeDictionary tcd) args
70+ guard $ workDone < 1000
71+ modify (1 +)
72+ directInstances <|> superclassInstances
73+ where
74+ directInstances :: StateT Work [] DictionaryValue
75+ directInstances = do
64− | tcd <- context'
76+ tcd <- lift context'
65− -- Make sure the type class name matches the one we are trying to satisfy
77+ -- Make sure the type class name matches the one we are trying to satisfy
66− , className' == tcdClassName tcd
78+ guard $ className' == tcdClassName tcd
67− -- Make sure the type unifies with the type in the type instance definition
79+ -- Make sure the type unifies with the type in the type instance definition
68− , subst <- maybeToList . (>>= verifySubstitution) . fmap concat $ zipWithM (typeHeadsAreEqual moduleName env) tys' (tcdInstanceTypes tcd)
80+ subst <- lift . maybeToList . (>>= verifySubstitution) . fmap concat $ zipWithM (typeHeadsAreEqual moduleName env) tys' (tcdInstanceTypes tcd)
69− -- Solve any necessary subgoals
81+ -- Solve any necessary subgoals
70− , args <- solveSubgoals subst (tcdDependencies tcd) ] ++
82+ args <- solveSubgoals subst (tcdDependencies tcd)
83+ return $ mkDictionary (canonicalizeDictionary tcd) args
71
84
72− -- Look for implementations via superclasses
85+ superclassInstances :: StateT Work [] DictionaryValue
73− [ SubclassDictionaryValue suDict superclass index
86+ superclassInstances = do
74− | trySuperclasses'
87+ guard trySuperclasses'
75− , (subclassName, (args, _, implies)) <- M.toList (typeClasses env)
88+ (subclassName, (args, _, implies)) <- lift $ M.toList (typeClasses env)
76− -- Try each superclass
89+ -- Try each superclass
77− , (index, (superclass, suTyArgs)) <- zip [0..] implies
90+ (index, (superclass, suTyArgs)) <- lift $ zip [0..] implies
78− -- Make sure the type class name matches the superclass name
91+ -- Make sure the type class name matches the superclass name
79− , className' == superclass
92+ guard $ className' == superclass
80− -- Make sure the types unify with the types in the superclass implication
93+ -- Make sure the types unify with the types in the superclass implication
81− , subst <- maybeToList . (>>= verifySubstitution) . fmap concat $ zipWithM (typeHeadsAreEqual moduleName env) tys' suTyArgs
94+ subst <- lift . maybeToList . (>>= verifySubstitution) . fmap concat $ zipWithM (typeHeadsAreEqual moduleName env) tys' suTyArgs
82− -- Finally, satisfy the subclass constraint
95+ -- Finally, satisfy the subclass constraint
83− , args' <- maybeToList $ mapM ((`lookup` subst) . fst) args
96+ args' <- lift . maybeToList $ mapM ((`lookup` subst) . fst) args
84− , suDict <- go True subclassName args' ]
97+ suDict <- go True subclassName args'
98+ return $ SubclassDictionaryValue suDict superclass index
85
99
86 -- Create dictionaries for subgoals which still need to be solved by calling go recursively
100 -- Create dictionaries for subgoals which still need to be solved by calling go recursively
87 -- E.g. the goal (Show a, Show b) => Show (Either a b) can be satisfied if the current type
101 -- E.g. the goal (Show a, Show b) => Show (Either a b) can be satisfied if the current type
88 -- unifies with Either a b, and we can satisfy the subgoals Show a and Show b recursively.
102 -- unifies with Either a b, and we can satisfy the subgoals Show a and Show b recursively.
89− solveSubgoals :: [(String, Type)] -> Maybe [Constraint] -> [Maybe [DictionaryValue]]
103+ solveSubgoals :: [(String, Type)] -> Maybe [Constraint] -> StateT Work [] (Maybe [DictionaryValue])
90 solveSubgoals _ Nothing = return Nothing
104 solveSubgoals _ Nothing = return Nothing
91 solveSubgoals subst (Just subgoals) = do
105 solveSubgoals subst (Just subgoals) = do
92 dict <- mapM (uncurry (go True) . second (map (replaceAllTypeVars subst))) subgoals
106 dict <- mapM (uncurry (go True) . second (map (replaceAllTypeVars subst))) subgoals
93 return $ Just dict
107 return $ Just dict
108+
94 -- Make a dictionary from subgoal dictionaries by applying the correct function
109 -- Make a dictionary from subgoal dictionaries by applying the correct function
95 mkDictionary :: Qualified Ident -> Maybe [DictionaryValue] -> DictionaryValue
110 mkDictionary :: Qualified Ident -> Maybe [DictionaryValue] -> DictionaryValue
96 mkDictionary fnName Nothing = LocalDictionaryValue fnName
111 mkDictionary fnName Nothing = LocalDictionaryValue fnName
97 mkDictionary fnName (Just []) = GlobalDictionaryValue fnName
112 mkDictionary fnName (Just []) = GlobalDictionaryValue fnName
98 mkDictionary fnName (Just dicts) = DependentDictionaryValue fnName dicts
113 mkDictionary fnName (Just dicts) = DependentDictionaryValue fnName dicts
114+
99 -- Turn a DictionaryValue into a Expr
115 -- Turn a DictionaryValue into a Expr
100 dictionaryValueToValue :: DictionaryValue -> Expr
116 dictionaryValueToValue :: DictionaryValue -> Expr
101 dictionaryValueToValue (LocalDictionaryValue fnName) = Var fnName
117 dictionaryValueToValue (LocalDictionaryValue fnName) = Var fnName
tests/Main.hs+17−15
@@ -23,10 +23,11 @@ import Data.Traversable (traverse)
23import Control.Monad
23import Control.Monad
24import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
24import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
25import Control.Monad.Reader (runReaderT)
25import Control.Monad.Reader (runReaderT)
26+import Control.Monad.Writer (runWriterT)
26import Control.Applicative
27import Control.Applicative
27import System.Exit
28import System.Exit
28import System.Process
29import System.Process
29−import System.FilePath (pathSeparator)
30+import System.FilePath ((</>))
30import System.Directory (getCurrentDirectory, getTemporaryDirectory, getDirectoryContents, findExecutable)
31import System.Directory (getCurrentDirectory, getTemporaryDirectory, getDirectoryContents, findExecutable)
31import Text.Parsec (ParseError)
32import Text.Parsec (ParseError)
32
33
@@ -35,11 +36,11 @@ readInput inputFiles = forM inputFiles $ \inputFile -> do
35 text <- readFile inputFile
36 text <- readFile inputFile
36 return (inputFile, text)
37 return (inputFile, text)
37
38
38−loadPrelude :: Either P.MultipleErrors (String, String, P.Environment)
39+loadPrelude :: [(FilePath, String)] -> Either P.MultipleErrors (String, String, P.Environment)
39−loadPrelude =
40+loadPrelude ms =
40− case P.parseModulesFromFiles id [("", P.prelude)] of
41+ case P.parseModulesFromFiles id ms of
41 Left parseError -> Left . P.errorMessage . P.ErrorParsingPrelude $ parseError
42 Left parseError -> Left . P.errorMessage . P.ErrorParsingPrelude $ parseError
42− Right ms -> runReaderT (P.compile (map snd ms) []) $ P.defaultCompileOptions { P.optionsAdditional = P.CompileOptions "Tests" [] [] }
43+ Right ms -> fmap fst . runWriterT $ runReaderT (P.compile (map snd ms) []) (P.defaultCompileOptions { P.optionsAdditional = P.CompileOptions "Tests" [] [] })
43
44
44compile :: P.Options P.Compile -> [FilePath] -> IO (Either P.MultipleErrors (String, String, P.Environment))
45compile :: P.Options P.Compile -> [FilePath] -> IO (Either P.MultipleErrors (String, String, P.Environment))
45compile opts inputFiles = do
46compile opts inputFiles = do
@@ -47,7 +48,7 @@ compile opts inputFiles = do
47 case modules of
48 case modules of
48 Left parseError ->
49 Left parseError ->
49 return . Left . P.errorMessage . P.ErrorParsingPrelude $ parseError
50 return . Left . P.errorMessage . P.ErrorParsingPrelude $ parseError
50− Right ms -> return $ runReaderT (P.compile (map snd ms) []) opts
51+ Right ms -> return $ fmap fst . runWriterT $ runReaderT (P.compile (map snd ms) []) opts
51
52
52assert :: FilePath -> P.Options P.Compile -> FilePath -> (Either P.MultipleErrors (String, String, P.Environment) -> IO (Maybe String)) -> IO ()
53assert :: FilePath -> P.Options P.Compile -> FilePath -> (Either P.MultipleErrors (String, String, P.Environment) -> IO (Maybe String)) -> IO ()
53assert preludeExterns opts inputFile f = do
54assert preludeExterns opts inputFile f = do
@@ -82,26 +83,27 @@ assertDoesNotCompile preludeExterns inputFile = do
82
83
83findNodeProcess :: IO (Maybe String)
84findNodeProcess :: IO (Maybe String)
84findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
85findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
86+ where
85− where names = ["nodejs", "node"]
87+ names = ["nodejs", "node"]
86
88
87main :: IO ()
89main :: IO ()
88main = do
90main = do
91+ cwd <- getCurrentDirectory
92+ prelude <- readInput [cwd </> "tests" </> "prelude.purs"]
89 putStrLn "Compiling Prelude"
93 putStrLn "Compiling Prelude"
90− case loadPrelude of
94+ case loadPrelude prelude of
91 Left errs -> putStrLn (P.prettyPrintMultipleErrors False errs) >> exitFailure
95 Left errs -> putStrLn (P.prettyPrintMultipleErrors False errs) >> exitFailure
92 Right (preludeJs, exts, _) -> do
96 Right (preludeJs, exts, _) -> do
93 tmp <- getTemporaryDirectory
97 tmp <- getTemporaryDirectory
94− let preludeExterns = tmp ++ pathSeparator : "prelude.externs"
98+ let preludeExterns = tmp </> "prelude.externs"
95 writeFile preludeExterns exts
99 writeFile preludeExterns exts
96 putStrLn $ "Wrote " ++ preludeExterns
100 putStrLn $ "Wrote " ++ preludeExterns
97− cd <- getCurrentDirectory
101+ let passing = cwd </> "examples" </> "passing"
98− let examples = cd ++ pathSeparator : "examples"
99− let passing = examples ++ pathSeparator : "passing"
100 passingTestCases <- getDirectoryContents passing
102 passingTestCases <- getDirectoryContents passing
101 forM_ passingTestCases $ \inputFile -> when (".purs" `isSuffixOf` inputFile) $
103 forM_ passingTestCases $ \inputFile -> when (".purs" `isSuffixOf` inputFile) $
102− assertCompiles preludeJs preludeExterns (passing ++ pathSeparator : inputFile)
104+ assertCompiles preludeJs preludeExterns (passing </> inputFile)
103− let failing = examples ++ pathSeparator : "failing"
105+ let failing = cwd </> "examples" </> "failing"
104 failingTestCases <- getDirectoryContents failing
106 failingTestCases <- getDirectoryContents failing
105 forM_ failingTestCases $ \inputFile -> when (".purs" `isSuffixOf` inputFile) $
107 forM_ failingTestCases $ \inputFile -> when (".purs" `isSuffixOf` inputFile) $
106− assertDoesNotCompile preludeExterns (failing ++ pathSeparator : inputFile)
108+ assertDoesNotCompile preludeExterns (failing </> inputFile)
107 exitSuccess
109 exitSuccess
prelude/prelude.purs → tests/prelude.pursrenamed+7−513
@@ -1,3 +1,8 @@
1+-- | This snapshot is provided for the purposes of running the test suite.
2+-- | It is not necessarily kept up to date with the official PureScript Prelude,
3+-- | and should not be used in user code.
4+-- | The official Prelude can be found at https://github.com/purescript/purescript-prelude
5+
1module Prelude
6module Prelude
2 ( Unit(..), unit
7 ( Unit(..), unit
3 , ($), (#)
8 , ($), (#)
@@ -30,99 +35,32 @@ module Prelude
30 , Show, show
35 , Show, show
31 ) where
36 ) where
32
37
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 {}
38 newtype Unit = Unit {}
40
39
41− -- | `unit` is the sole inhabitant of the `Unit` type.
42 unit :: Unit
40 unit :: Unit
43 unit = Unit {}
41 unit = Unit {}
44
42
45 infixr 0 $
43 infixr 0 $
46 infixl 0 #
44 infixl 0 #
47
45
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
46 ($) :: forall a b. (a -> b) -> a -> b
63 ($) f x = f x
47 ($) f x = f x
64
48
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
49 (#) :: forall a b. a -> (a -> b) -> b
80 (#) x f = f x
50 (#) x f = f x
81
51
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
52 flip :: forall a b c. (a -> b -> c) -> b -> a -> c
88 flip f b a = f a b
53 flip f b a = f a b
89
54
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
55 const :: forall a b. a -> b -> a
96 const a _ = a
56 const a _ = a
97
57
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
58 asTypeOf :: forall a. a -> a -> a
108 asTypeOf x _ = x
59 asTypeOf x _ = x
109
60
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
61 otherwise :: Boolean
117 otherwise = true
62 otherwise = true
118
63
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
64 foreign import cons
127 """
65 """
128 function cons(e) {
66 function cons(e) {
@@ -134,42 +72,21 @@ module Prelude
134
72
135 infixr 6 :
73 infixr 6 :
136
74
137− -- | An infix alias for `cons`.
138− -- |
139− -- | Note, the running time of this function is `O(n)`.
140 (:) :: forall a. a -> [a] -> [a]
75 (:) :: forall a. a -> [a] -> [a]
141 (:) = cons
76 (:) = cons
142
77
143 infixr 9 >>>
78 infixr 9 >>>
144 infixr 9 <<<
79 infixr 9 <<<
145
80
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
81 class Semigroupoid a where
156 (<<<) :: forall b c d. a c d -> a b c -> a b d
82 (<<<) :: forall b c d. a c d -> a b c -> a b d
157
83
158 instance semigroupoidArr :: Semigroupoid (->) where
84 instance semigroupoidArr :: Semigroupoid (->) where
159 (<<<) f g x = f (g x)
85 (<<<) f g x = f (g x)
160
86
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
87 (>>>) :: forall a b c d. (Semigroupoid a) => a b c -> a c d -> a b d
163 (>>>) f g = g <<< f
88 (>>>) f g = g <<< f
164
89
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
90 class (Semigroupoid a) <= Category a where
174 id :: forall t. a t t
91 id :: forall t. a t t
175
92
@@ -179,194 +96,55 @@ module Prelude
179 infixl 4 <$>
96 infixl 4 <$>
180 infixl 1 <#>
97 infixl 1 <#>
181
98
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
99 class Functor f where
194 (<$>) :: forall a b. (a -> b) -> f a -> f b
100 (<$>) :: forall a b. (a -> b) -> f a -> f b
195
101
196 instance functorArr :: Functor ((->) r) where
102 instance functorArr :: Functor ((->) r) where
197 (<$>) = (<<<)
103 (<$>) = (<<<)
198
104
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
105 (<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
205 (<#>) fa f = f <$> fa
106 (<#>) fa f = f <$> fa
206
107
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
108 void :: forall f a. (Functor f) => f a -> f Unit
220 void fa = const unit <$> fa
109 void fa = const unit <$> fa
221
110
222 infixl 4 <*>
111 infixl 4 <*>
223
112
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
113 class (Functor f) <= Apply f where
247 (<*>) :: forall a b. f (a -> b) -> f a -> f b
114 (<*>) :: forall a b. f (a -> b) -> f a -> f b
248
115
249 instance applyArr :: Apply ((->) r) where
116 instance applyArr :: Apply ((->) r) where
250 (<*>) f g x = f x (g x)
117 (<*>) f g x = f x (g x)
251
118
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
119 class (Apply f) <= Applicative f where
271 pure :: forall a. a -> f a
120 pure :: forall a. a -> f a
272
121
273 instance applicativeArr :: Applicative ((->) r) where
122 instance applicativeArr :: Applicative ((->) r) where
274 pure = const
123 pure = const
275
124
276− -- | `return` is an alias for `pure`.
277 return :: forall m a. (Applicative m) => a -> m a
125 return :: forall m a. (Applicative m) => a -> m a
278 return = pure
126 return = pure
279
127
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
128 liftA1 :: forall f a b. (Applicative f) => (a -> b) -> f a -> f b
293 liftA1 f a = pure f <*> a
129 liftA1 f a = pure f <*> a
294
130
295 infixl 1 >>=
131 infixl 1 >>=
296
132
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
133 class (Apply m) <= Bind m where
324 (>>=) :: forall a b. m a -> (a -> m b) -> m b
134 (>>=) :: forall a b. m a -> (a -> m b) -> m b
325
135
326 instance bindArr :: Bind ((->) r) where
136 instance bindArr :: Bind ((->) r) where
327 (>>=) m f x = f (m x) x
137 (>>=) m f x = f (m x) x
328
138
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
139 class (Applicative m, Bind m) <= Monad m
340
140
341 instance monadArr :: Monad ((->) r)
141 instance monadArr :: Monad ((->) r)
342
142
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
143 liftM1 :: forall m a b. (Monad m) => (a -> b) -> m a -> m b
355 liftM1 f a = do
144 liftM1 f a = do
356 a' <- a
145 a' <- a
357 return (f a')
146 return (f a')
358
147
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
148 ap :: forall m a b. (Monad m) => m (a -> b) -> m a -> m b
371 ap f a = do
149 ap f a = do
372 f' <- f
150 f' <- f
@@ -376,18 +154,9 @@ module Prelude
376 infixr 5 <>
154 infixr 5 <>
377 infixr 5 ++
155 infixr 5 ++
378
156
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
157 class Semigroup a where
388 (<>) :: a -> a -> a
158 (<>) :: a -> a -> a
389
159
390− -- | `(++)` is an alias for `(<>)`.
391 (++) :: forall s. (Semigroup s) => s -> s -> s
160 (++) :: forall s. (Semigroup s) => s -> s -> s
392 (++) = (<>)
161 (++) = (<>)
393
162
@@ -417,22 +186,6 @@ module Prelude
417 infixl 6 +
186 infixl 6 +
418 infixl 7 *
187 infixl 7 *
419
188
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
189 class Semiring a where
437 (+) :: a -> a -> a
190 (+) :: a -> a -> a
438 zero :: a
191 zero :: a
@@ -453,13 +206,6 @@ module Prelude
453
206
454 infixl 6 -
207 infixl 6 -
455
208
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
209 class (Semiring a) <= Ring a where
464 (-) :: a -> a -> a
210 (-) :: a -> a -> a
465
211
@@ -474,13 +220,6 @@ module Prelude
474
220
475 infixl 7 /
221 infixl 7 /
476
222
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
223 class (Semiring a) <= ModuloSemiring a where
485 (/) :: a -> a -> a
224 (/) :: a -> a -> a
486 mod :: a -> a -> a
225 mod :: a -> a -> a
@@ -493,27 +232,12 @@ module Prelude
493 (/) _ _ = unit
232 (/) _ _ = unit
494 mod _ _ = unit
233 mod _ _ = unit
495
234
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
235 class (Ring a, ModuloSemiring a) <= DivisionRing a
506
236
507 instance divisionRingNumber :: DivisionRing Number
237 instance divisionRingNumber :: DivisionRing Number
508
238
509 instance divisionRingUnit :: DivisionRing Unit
239 instance divisionRingUnit :: DivisionRing Unit
510
240
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
241 class (DivisionRing a) <= Num a
518
242
519 instance numNumber :: Num Number
243 instance numNumber :: Num Number
@@ -559,16 +283,6 @@ module Prelude
559 infix 4 ==
283 infix 4 ==
560 infix 4 /=
284 infix 4 /=
561
285
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
286 class Eq a where
573 (==) :: a -> a -> Boolean
287 (==) :: a -> a -> Boolean
574 (/=) :: a -> a -> Boolean
288 (/=) :: a -> a -> Boolean
@@ -633,21 +347,8 @@ module Prelude
633 }
347 }
634 """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
348 """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
635
349
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
350 data Ordering = LT | GT | EQ
643
351
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
352 class (Eq a) <= Ord a where
652 compare :: a -> a -> Ordering
353 compare :: a -> a -> Ordering
653
354
@@ -688,25 +389,21 @@ module Prelude
688 infixl 4 <=
389 infixl 4 <=
689 infixl 4 >=
390 infixl 4 >=
690
391
691− -- | Test whether one value is _strictly less than_ another.
692 (<) :: forall a. (Ord a) => a -> a -> Boolean
392 (<) :: forall a. (Ord a) => a -> a -> Boolean
693 (<) a1 a2 = case a1 `compare` a2 of
393 (<) a1 a2 = case a1 `compare` a2 of
694 LT -> true
394 LT -> true
695 _ -> false
395 _ -> false
696
396
697− -- | Test whether one value is _strictly greater than_ another.
698 (>) :: forall a. (Ord a) => a -> a -> Boolean
397 (>) :: forall a. (Ord a) => a -> a -> Boolean
699 (>) a1 a2 = case a1 `compare` a2 of
398 (>) a1 a2 = case a1 `compare` a2 of
700 GT -> true
399 GT -> true
701 _ -> false
400 _ -> false
702
401
703− -- | Test whether one value is _non-strictly less than_ another.
704 (<=) :: forall a. (Ord a) => a -> a -> Boolean
402 (<=) :: forall a. (Ord a) => a -> a -> Boolean
705 (<=) a1 a2 = case a1 `compare` a2 of
403 (<=) a1 a2 = case a1 `compare` a2 of
706 GT -> false
404 GT -> false
707 _ -> true
405 _ -> true
708
406
709− -- | Test whether one value is _non-strictly greater than_ another.
710 (>=) :: forall a. (Ord a) => a -> a -> Boolean
407 (>=) :: forall a. (Ord a) => a -> a -> Boolean
711 (>=) a1 a2 = case a1 `compare` a2 of
408 (>=) a1 a2 = case a1 `compare` a2 of
712 LT -> false
409 LT -> false
@@ -730,12 +427,6 @@ module Prelude
730 }
427 }
731 """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
428 """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
732
429
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
430 class (Ord a) <= Bounded a where
740 top :: a
431 top :: a
741 bottom :: a
432 bottom :: a
@@ -752,24 +443,6 @@ module Prelude
752 top = GT
443 top = GT
753 bottom = LT
444 bottom = LT
754
445
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
446 class (Ord a) <= Lattice a where
774 sup :: a -> a -> a
447 sup :: a -> a -> a
775 inf :: a -> a -> a
448 inf :: a -> a -> a
@@ -785,43 +458,18 @@ module Prelude
785 infixr 2 ||
458 infixr 2 ||
786 infixr 3 &&
459 infixr 3 &&
787
460
788− -- | The `sup` operator.
789 (||) :: forall a. (Lattice a) => a -> a -> a
461 (||) :: forall a. (Lattice a) => a -> a -> a
790 (||) = sup
462 (||) = sup
791
463
792− -- | The `inf` operator.
793 (&&) :: forall a. (Lattice a) => a -> a -> a
464 (&&) :: forall a. (Lattice a) => a -> a -> a
794 (&&) = inf
465 (&&) = inf
795
466
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
467 class (Bounded a, Lattice a) <= BoundedLattice a
809
468
810 instance boundedLatticeBoolean :: BoundedLattice Boolean
469 instance boundedLatticeBoolean :: BoundedLattice Boolean
811
470
812 instance boundedLatticeUnit :: BoundedLattice Unit
471 instance boundedLatticeUnit :: BoundedLattice Unit
813
472
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
473 class (BoundedLattice a) <= ComplementedLattice a where
826 not :: a -> a
474 not :: a -> a
827
475
@@ -831,24 +479,12 @@ module Prelude
831 instance complementedLatticeUnit :: ComplementedLattice Unit where
479 instance complementedLatticeUnit :: ComplementedLattice Unit where
832 not _ = unit
480 not _ = unit
833
481
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
482 class (Lattice a) <= DistributiveLattice a
842
483
843 instance distributiveLatticeBoolean :: DistributiveLattice Boolean
484 instance distributiveLatticeBoolean :: DistributiveLattice Boolean
844
485
845 instance distributiveLatticeUnit :: DistributiveLattice Unit
486 instance distributiveLatticeUnit :: DistributiveLattice Unit
846
487
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
488 class (ComplementedLattice a, DistributiveLattice a) <= BooleanAlgebra a
853
489
854 instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
490 instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
@@ -880,12 +516,6 @@ module Prelude
880 }
516 }
881 """ :: Boolean -> Boolean
517 """ :: Boolean -> Boolean
882
518
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
519 class Show a where
890 show :: a -> String
520 show :: a -> String
891
521
@@ -939,51 +569,31 @@ module Prelude
939
569
940module Data.Function where
570module Data.Function where
941
571
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
572 on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
951 on f g x y = g x `f` g y
573 on f g x y = g x `f` g y
952
574
953− -- | A function of zero arguments
954 foreign import data Fn0 :: * -> *
575 foreign import data Fn0 :: * -> *
955
576
956− -- | A function of one argument
957 foreign import data Fn1 :: * -> * -> *
577 foreign import data Fn1 :: * -> * -> *
958
578
959− -- | A function of two arguments
960 foreign import data Fn2 :: * -> * -> * -> *
579 foreign import data Fn2 :: * -> * -> * -> *
961
580
962− -- | A function of three arguments
963 foreign import data Fn3 :: * -> * -> * -> * -> *
581 foreign import data Fn3 :: * -> * -> * -> * -> *
964
582
965− -- | A function of four arguments
966 foreign import data Fn4 :: * -> * -> * -> * -> * -> *
583 foreign import data Fn4 :: * -> * -> * -> * -> * -> *
967
584
968− -- | A function of five arguments
969 foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
585 foreign import data Fn5 :: * -> * -> * -> * -> * -> * -> *
970
586
971− -- | A function of six arguments
972 foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
587 foreign import data Fn6 :: * -> * -> * -> * -> * -> * -> * -> *
973
588
974− -- | A function of seven arguments
975 foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
589 foreign import data Fn7 :: * -> * -> * -> * -> * -> * -> * -> * -> *
976
590
977− -- | A function of eight arguments
978 foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
591 foreign import data Fn8 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> *
979
592
980− -- | A function of nine arguments
981 foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
593 foreign import data Fn9 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
982
594
983− -- | A function of ten arguments
984 foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
595 foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
985
596
986− -- | Create a function of no arguments
987 foreign import mkFn0
597 foreign import mkFn0
988 """
598 """
989 function mkFn0(fn) {
599 function mkFn0(fn) {
@@ -993,7 +603,6 @@ module Data.Function where
993 }
603 }
994 """ :: forall a. (Unit -> a) -> Fn0 a
604 """ :: forall a. (Unit -> a) -> Fn0 a
995
605
996− -- | Create a function of one argument
997 foreign import mkFn1
606 foreign import mkFn1
998 """
607 """
999 function mkFn1(fn) {
608 function mkFn1(fn) {
@@ -1003,7 +612,6 @@ module Data.Function where
1003 }
612 }
1004 """ :: forall a b. (a -> b) -> Fn1 a b
613 """ :: forall a b. (a -> b) -> Fn1 a b
1005
614
1006− -- | Create a function of two arguments from a curried function
1007 foreign import mkFn2
615 foreign import mkFn2
1008 """
616 """
1009 function mkFn2(fn) {
617 function mkFn2(fn) {
@@ -1013,7 +621,6 @@ module Data.Function where
1013 }
621 }
1014 """ :: forall a b c. (a -> b -> c) -> Fn2 a b c
622 """ :: forall a b c. (a -> b -> c) -> Fn2 a b c
1015
623
1016− -- | Create a function of three arguments from a curried function
1017 foreign import mkFn3
624 foreign import mkFn3
1018 """
625 """
1019 function mkFn3(fn) {
626 function mkFn3(fn) {
@@ -1023,7 +630,6 @@ module Data.Function where
1023 }
630 }
1024 """ :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
631 """ :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
1025
632
1026− -- | Create a function of four arguments from a curried function
1027 foreign import mkFn4
633 foreign import mkFn4
1028 """
634 """
1029 function mkFn4(fn) {
635 function mkFn4(fn) {
@@ -1033,7 +639,6 @@ module Data.Function where
1033 }
639 }
1034 """ :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
640 """ :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
1035
641
1036− -- | Create a function of five arguments from a curried function
1037 foreign import mkFn5
642 foreign import mkFn5
1038 """
643 """
1039 function mkFn5(fn) {
644 function mkFn5(fn) {
@@ -1043,7 +648,6 @@ module Data.Function where
1043 }
648 }
1044 """ :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
649 """ :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
1045
650
1046− -- | Create a function of six arguments from a curried function
1047 foreign import mkFn6
651 foreign import mkFn6
1048 """
652 """
1049 function mkFn6(fn) {
653 function mkFn6(fn) {
@@ -1053,7 +657,6 @@ module Data.Function where
1053 }
657 }
1054 """ :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
658 """ :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
1055
659
1056− -- | Create a function of seven arguments from a curried function
1057 foreign import mkFn7
660 foreign import mkFn7
1058 """
661 """
1059 function mkFn7(fn) {
662 function mkFn7(fn) {
@@ -1063,7 +666,6 @@ module Data.Function where
1063 }
666 }
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
667 """ :: 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
668
1066− -- | Create a function of eight arguments from a curried function
1067 foreign import mkFn8
669 foreign import mkFn8
1068 """
670 """
1069 function mkFn8(fn) {
671 function mkFn8(fn) {
@@ -1073,7 +675,6 @@ module Data.Function where
1073 }
675 }
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
676 """ :: 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
677
1076− -- | Create a function of nine arguments from a curried function
1077 foreign import mkFn9
678 foreign import mkFn9
1078 """
679 """
1079 function mkFn9(fn) {
680 function mkFn9(fn) {
@@ -1083,7 +684,6 @@ module Data.Function where
1083 }
684 }
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
685 """ :: 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
686
1086− -- | Create a function of ten arguments from a curried function
1087 foreign import mkFn10
687 foreign import mkFn10
1088 """
688 """
1089 function mkFn10(fn) {
689 function mkFn10(fn) {
@@ -1093,7 +693,6 @@ module Data.Function where
1093 }
693 }
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
694 """ :: 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
695
1096− -- | Apply a function of no arguments
1097 foreign import runFn0
696 foreign import runFn0
1098 """
697 """
1099 function runFn0(fn) {
698 function runFn0(fn) {
@@ -1101,7 +700,6 @@ module Data.Function where
1101 }
700 }
1102 """ :: forall a. Fn0 a -> a
701 """ :: forall a. Fn0 a -> a
1103
702
1104− -- | Apply a function of one argument
1105 foreign import runFn1
703 foreign import runFn1
1106 """
704 """
1107 function runFn1(fn) {
705 function runFn1(fn) {
@@ -1111,7 +709,6 @@ module Data.Function where
1111 }
709 }
1112 """ :: forall a b. Fn1 a b -> a -> b
710 """ :: forall a b. Fn1 a b -> a -> b
1113
711
1114− -- | Apply a function of two arguments
1115 foreign import runFn2
712 foreign import runFn2
1116 """
713 """
1117 function runFn2(fn) {
714 function runFn2(fn) {
@@ -1123,7 +720,6 @@ module Data.Function where
1123 }
720 }
1124 """ :: forall a b c. Fn2 a b c -> a -> b -> c
721 """ :: forall a b c. Fn2 a b c -> a -> b -> c
1125
722
1126− -- | Apply a function of three arguments
1127 foreign import runFn3
723 foreign import runFn3
1128 """
724 """
1129 function runFn3(fn) {
725 function runFn3(fn) {
@@ -1137,7 +733,6 @@ module Data.Function where
1137 }
733 }
1138 """ :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
734 """ :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
1139
735
1140− -- | Apply a function of four arguments
1141 foreign import runFn4
736 foreign import runFn4
1142 """
737 """
1143 function runFn4(fn) {
738 function runFn4(fn) {
@@ -1153,7 +748,6 @@ module Data.Function where
1153 }
748 }
1154 """ :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
749 """ :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
1155
750
1156− -- | Apply a function of five arguments
1157 foreign import runFn5
751 foreign import runFn5
1158 """
752 """
1159 function runFn5(fn) {
753 function runFn5(fn) {
@@ -1171,7 +765,6 @@ module Data.Function where
1171 }
765 }
1172 """ :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
766 """ :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
1173
767
1174− -- | Apply a function of six arguments
1175 foreign import runFn6
768 foreign import runFn6
1176 """
769 """
1177 function runFn6(fn) {
770 function runFn6(fn) {
@@ -1191,7 +784,6 @@ module Data.Function where
1191 }
784 }
1192 """ :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
785 """ :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
1193
786
1194− -- | Apply a function of seven arguments
1195 foreign import runFn7
787 foreign import runFn7
1196 """
788 """
1197 function runFn7(fn) {
789 function runFn7(fn) {
@@ -1213,7 +805,6 @@ module Data.Function where
1213 }
805 }
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
806 """ :: 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
807
1216− -- | Apply a function of eight arguments
1217 foreign import runFn8
808 foreign import runFn8
1218 """
809 """
1219 function runFn8(fn) {
810 function runFn8(fn) {
@@ -1237,7 +828,6 @@ module Data.Function where
1237 }
828 }
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
829 """ :: 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
830
1240− -- | Apply a function of nine arguments
1241 foreign import runFn9
831 foreign import runFn9
1242 """
832 """
1243 function runFn9(fn) {
833 function runFn9(fn) {
@@ -1263,7 +853,6 @@ module Data.Function where
1263 }
853 }
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
854 """ :: 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
855
1266− -- | Apply a function of ten arguments
1267 foreign import runFn10
856 foreign import runFn10
1268 """
857 """
1269 function runFn10(fn) {
858 function runFn10(fn) {
@@ -1293,9 +882,6 @@ module Data.Function where
1293
882
1294module Prelude.Unsafe where
883module Prelude.Unsafe where
1295
884
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
885 foreign import unsafeIndex
1300 """
886 """
1301 function unsafeIndex(xs) {
887 function unsafeIndex(xs) {
@@ -1309,14 +895,9 @@ module Control.Monad.Eff
1309 ( Eff()
895 ( Eff()
1310 , Pure()
896 , Pure()
1311 , runPure
897 , runPure
1312− , untilE, whileE, forE, foreachE
898+ , untilE, whileE
1313 ) where
899 ) where
1314
900
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 :: # ! -> * -> *
901 foreign import data Eff :: # ! -> * -> *
1321
902
1322 foreign import returnE
903 foreign import returnE
@@ -1339,15 +920,8 @@ module Control.Monad.Eff
1339 }
920 }
1340 """ :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
921 """ :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
1341
922
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
923 type Pure a = forall e. Eff e a
1346
924
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
925 foreign import runPure
1352 """
926 """
1353 function runPure(f) {
927 function runPure(f) {
@@ -1369,10 +943,6 @@ module Control.Monad.Eff
1369
943
1370 instance monadEff :: Monad (Eff e)
944 instance monadEff :: Monad (Eff e)
1371
945
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
946 foreign import untilE
1377 """
947 """
1378 function untilE(f) {
948 function untilE(f) {
@@ -1383,10 +953,6 @@ module Control.Monad.Eff
1383 }
953 }
1384 """ :: forall e. Eff e Boolean -> Eff e Unit
954 """ :: forall e. Eff e Boolean -> Eff e Unit
1385
955
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
956 foreign import whileE
1391 """
957 """
1392 function whileE(f) {
958 function whileE(f) {
@@ -1401,63 +967,12 @@ module Control.Monad.Eff
1401 }
967 }
1402 """ :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
968 """ :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
1403
969
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−
1453module Debug.Trace where
970module Debug.Trace where
1454
971
1455 import Control.Monad.Eff
972 import Control.Monad.Eff
1456
973
1457− -- | The `Trace` effect represents those computations which write to the console.
1458 foreign import data Trace :: !
974 foreign import data Trace :: !
1459
975
1460− -- | Write a `String` to the console.
1461 foreign import trace
976 foreign import trace
1462 """
977 """
1463 function trace(s) {
978 function trace(s) {
@@ -1468,7 +983,6 @@ module Debug.Trace where
1468 }
983 }
1469 """ :: forall r. String -> Eff (trace :: Trace | r) Unit
984 """ :: forall r. String -> Eff (trace :: Trace | r) Unit
1470
985
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
986 print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
1473 print o = trace (show o)
987 print o = trace (show o)
1474
988
@@ -1476,17 +990,10 @@ module Control.Monad.ST where
1476
990
1477 import Control.Monad.Eff
991 import Control.Monad.Eff
1478
992
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 :: * -> !
993 foreign import data ST :: * -> !
1485
994
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 :: * -> * -> *
995 foreign import data STRef :: * -> * -> *
1488
996
1489− -- | Create a new mutable reference.
1490 foreign import newSTRef
997 foreign import newSTRef
1491 """
998 """
1492 function newSTRef(val) {
999 function newSTRef(val) {
@@ -1496,7 +1003,6 @@ module Control.Monad.ST where
1496 }
1003 }
1497 """ :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1004 """ :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1498
1005
1499− -- | Read the current value of a mutable reference.
1500 foreign import readSTRef
1006 foreign import readSTRef
1501 """
1007 """
1502 function readSTRef(ref) {
1008 function readSTRef(ref) {
@@ -1506,7 +1012,6 @@ module Control.Monad.ST where
1506 }
1012 }
1507 """ :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1013 """ :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1508
1014
1509− -- | Modify the value of a mutable reference by applying a function to the current value.
1510 foreign import modifySTRef
1015 foreign import modifySTRef
1511 """
1016 """
1512 function modifySTRef(ref) {
1017 function modifySTRef(ref) {
@@ -1518,7 +1023,6 @@ module Control.Monad.ST where
1518 }
1023 }
1519 """ :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1024 """ :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1520
1025
1521− -- | Set the value of a mutable reference.
1522 foreign import writeSTRef
1026 foreign import writeSTRef
1523 """
1027 """
1524 function writeSTRef(ref) {
1028 function writeSTRef(ref) {
@@ -1530,12 +1034,6 @@ module Control.Monad.ST where
1530 }
1034 }
1531 """ :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1035 """ :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1532
1036
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
1037 foreign import runST
1540 """
1038 """
1541 function runST(f) {
1039 function runST(f) {
@@ -1543,9 +1041,5 @@ module Control.Monad.ST where
1543 }
1041 }
1544 """ :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1042 """ :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1545
1043
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
1044 pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
1551− pureST st = runPure (runST st)
1045+ pureST st = runPure (runST st)