@@ -13,8 +13,13 @@ module Prelude
1313 , Applicative, pure, liftA1
1414 , Bind, (>>=)
1515 , Monad, return, liftM1, ap
16− , Num, (+), (-), (*), (/), (%)
16+ , Semiring, (+), zero, (*), one
17+ , ModuloSemiring, (/), mod
18+ , Ring, (-)
19+ , (%)
1720 , negate
21+ , DivisionRing
22+ , Num
1823 , Eq, (==), (/=), refEq, refIneq
1924 , Ord, Ordering(..), compare, (<), (>), (<=), (>=)
2025 , Bits, (.&.), (.|.), (.^.), shl, shr, zshr, complement
@@ -24,15 +29,32 @@ module Prelude
2429 , Unit(..), unit
2530 ) where
2631
32+ -- | An alias for `true`, which can be useful in guard clauses:
33+ -- |
34+ -- | E.g.
35+ -- |
36+ -- | max x y | x >= y = x
37+ -- | | otherwise = y
2738 otherwise :: Boolean
2839 otherwise = true
2940
41+ -- | Flips the order of the arguments to a function of two arguments.
3042 flip :: forall a b c. (a -> b -> c) -> b -> a -> c
3143 flip f b a = f a b
3244
45+ -- | Returns its first argument and ignores its second.
3346 const :: forall a b. a -> b -> a
3447 const a _ = a
3548
49+ -- | This function returns its first argument, and can be used to assert type equalities.
50+ -- | This can be useful when types are otherwise ambiguous.
51+ -- |
52+ -- | E.g.
53+ -- |
54+ -- | main = print $ [] `asTypeOf` [0]
55+ -- |
56+ -- | If instead, we had written `main = print []`, the type of the argument `[]` would have
57+ -- | been ambiguous, resulting in a compile-time error.
3658 asTypeOf :: forall a. a -> a -> a
3759 asTypeOf x _ = x
3860
@@ -69,19 +91,23 @@ module Prelude
6991 (:) = cons
7092
7193 foreign import cons
72− "function cons(e) {\
73− \ return function(l) {\
74− \ return [e].concat(l);\
75− \ };\
76− \}" :: forall a. a -> [a] -> [a]
94+ """
95+ function cons(e) {
96+ return function(l) {
97+ return [e].concat(l);
98+ };
99+ }
100+ """ :: forall a. a -> [a] -> [a]
77101
78102 class Show a where
79103 show :: a -> String
80104
81105 foreign import showStringImpl
82− "function showStringImpl(s) {\
83− \ return JSON.stringify(s);\
84− \}" :: String -> String
106+ """
107+ function showStringImpl(s) {
108+ return JSON.stringify(s);
109+ }
110+ """ :: String -> String
85111
86112 instance showUnit :: Show Unit where
87113 show (Unit {}) = "Unit {}"
@@ -93,23 +119,28 @@ module Prelude
93119 show true = "true"
94120 show false = "false"
95121
96− foreign import showNumberImpl "function showNumberImpl(n) {\
97− \ return n.toString();\
98− \}" :: Number -> String
122+ foreign import showNumberImpl
123+ """
124+ function showNumberImpl(n) {
125+ return n.toString();
126+ }
127+ """ :: Number -> String
99128
100129 instance showNumber :: Show Number where
101130 show = showNumberImpl
102131
103132 foreign import showArrayImpl
104− "function showArrayImpl(f) {\
105− \ return function(xs) {\
106− \ var ss = [];\
107− \ for (var i = 0, l = xs.length; i < l; i++) {\
108− \ ss[i] = f(xs[i]);\
109− \ }\
110− \ return '[' + ss.join(',') + ']';\
111− \ };\
112− \}" :: forall a. (a -> String) -> [a] -> String
133+ """
134+ function showArrayImpl(f) {
135+ return function(xs) {
136+ var ss = [];
137+ for (var i = 0, l = xs.length; i < l; i++) {
138+ ss[i] = f(xs[i]);
139+ }
140+ return '[' + ss.join(',') + ']';
141+ };
142+ }
143+ """ :: forall a. (a -> String) -> [a] -> String
113144
114145 instance showArray :: (Show a) => Show [a] where
115146 show = showArrayImpl show
@@ -179,55 +210,96 @@ module Prelude
179210 infixl 6 -
180211 infixl 6 +
181212
182− class Num a where
183− (+) :: a -> a -> a
184− (-) :: a -> a -> a
185− (*) :: a -> a -> a
213+ -- | Addition and multiplication
214+ class Semiring a where
215+ (+) :: a -> a -> a
216+ zero :: a
217+ (*) :: a -> a -> a
218+ one :: a
219+
220+ -- | Semiring with modulo operation and division where
221+ -- | ```a / b * b + (a `mod` b) = a```
222+ class (Semiring a) <= ModuloSemiring a where
186223 (/) :: a -> a -> a
187− (%) :: a -> a -> a
188− negate :: a -> a
189−
190− foreign import numAdd "function numAdd(n1) {\
191− \ return function(n2) {\
192− \ return n1 + n2;\
193− \ };\
194− \}" :: Number -> Number -> Number
195−
196− foreign import numSub "function numSub(n1) {\
197− \ return function(n2) {\
198− \ return n1 - n2;\
199− \ };\
200− \}" :: Number -> Number -> Number
201−
202− foreign import numMul "function numMul(n1) {\
203− \ return function(n2) {\
204− \ return n1 * n2;\
205− \ };\
206− \}" :: Number -> Number -> Number
207−
208− foreign import numDiv "function numDiv(n1) {\
209− \ return function(n2) {\
210− \ return n1 / n2;\
211− \ };\
212− \}" :: Number -> Number -> Number
213−
214− foreign import numMod "function numMod(n1) {\
215− \ return function(n2) {\
216− \ return n1 % n2;\
217− \ };\
218− \}" :: Number -> Number -> Number
219−
220− foreign import numNegate "function numNegate(n) {\
221− \ return -n;\
222− \}" :: Number -> Number
223−
224− instance numNumber :: Num Number where
224+ mod :: a -> a -> a
225+
226+ -- | Addition, multiplication, and subtraction
227+ class (Semiring a) <= Ring a where
228+ (-) :: a -> a -> a
229+
230+ negate :: forall a. (Ring a) => a -> a
231+ negate a = zero - a
232+
233+ -- | Ring where every nonzero element has a multiplicative inverse (possibly
234+ -- | a non-commutative field) so that ```a `mod` b = zero```
235+ class (Ring a, ModuloSemiring a) <= DivisionRing a
236+
237+ -- | A commutative field
238+ class (DivisionRing a) <= Num a
239+
240+ foreign import numAdd
241+ """
242+ function numAdd(n1) {
243+ return function(n2) {
244+ return n1 + n2;
245+ };
246+ }
247+ """ :: Number -> Number -> Number
248+
249+ foreign import numSub
250+ """
251+ function numSub(n1) {
252+ return function(n2) {
253+ return n1 - n2;
254+ };
255+ }
256+ """ :: Number -> Number -> Number
257+
258+ foreign import numMul
259+ """
260+ function numMul(n1) {
261+ return function(n2) {
262+ return n1 * n2;
263+ };
264+ }
265+ """ :: Number -> Number -> Number
266+
267+ foreign import numDiv
268+ """
269+ function numDiv(n1) {
270+ return function(n2) {
271+ return n1 / n2;
272+ };
273+ }
274+ """ :: Number -> Number -> Number
275+
276+ foreign import numMod
277+ """
278+ function numMod(n1) {
279+ return function(n2) {
280+ return n1 % n2;
281+ };
282+ }
283+ """ :: Number -> Number -> Number
284+
285+ (%) = numMod
286+
287+ instance semiringNumber :: Semiring Number where
225288 (+) = numAdd
226− (-) = numSub
289+ zero = 0
227290 (*) = numMul
291+ one = 1
292+
293+ instance ringNumber :: Ring Number where
294+ (-) = numSub
295+
296+ instance moduloSemiringNumber :: ModuloSemiring Number where
228297 (/) = numDiv
229− (%) = numMod
230− negate = numNegate
298+ mod _ _ = 0
299+
300+ instance divisionRingNumber :: DivisionRing Number
301+
302+ instance numNumber :: Num Number
231303
232304 newtype Unit = Unit {}
233305
@@ -242,18 +314,22 @@ module Prelude
242314 (/=) :: a -> a -> Boolean
243315
244316 foreign import refEq
245− "function refEq(r1) {\
246− \ return function(r2) {\
247− \ return r1 === r2;\
248− \ };\
249− \}" :: forall a. a -> a -> Boolean
317+ """
318+ function refEq(r1) {
319+ return function(r2) {
320+ return r1 === r2;
321+ };
322+ }
323+ """ :: forall a. a -> a -> Boolean
250324
251325 foreign import refIneq
252− "function refIneq(r1) {\
253− \ return function(r2) {\
254− \ return r1 !== r2;\
255− \ };\
256− \}" :: forall a. a -> a -> Boolean
326+ """
327+ function refIneq(r1) {
328+ return function(r2) {
329+ return r1 !== r2;
330+ };
331+ }
332+ """ :: forall a. a -> a -> Boolean
257333
258334 instance eqUnit :: Eq Unit where
259335 (==) (Unit {}) (Unit {}) = true
@@ -272,17 +348,19 @@ module Prelude
272348 (/=) = refIneq
273349
274350 foreign import eqArrayImpl
275− "function eqArrayImpl(f) {\
276− \ return function(xs) {\
277− \ return function(ys) {\
278− \ if (xs.length !== ys.length) return false;\
279− \ for (var i = 0; i < xs.length; i++) {\
280− \ if (!f(xs[i])(ys[i])) return false;\
281− \ }\
282− \ return true;\
283− \ };\
284− \ };\
285− \}" :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
351+ """
352+ function eqArrayImpl(f) {
353+ return function(xs) {
354+ return function(ys) {
355+ if (xs.length !== ys.length) return false;
356+ for (var i = 0; i < xs.length; i++) {
357+ if (!f(xs[i])(ys[i])) return false;
358+ }
359+ return true;
360+ };
361+ };
362+ }
363+ """ :: forall a. (a -> a -> Boolean) -> [a] -> [a] -> Boolean
286364
287365 instance eqArray :: (Eq a) => Eq [a] where
288366 (==) xs ys = eqArrayImpl (==) xs ys
@@ -334,17 +412,19 @@ module Prelude
334412 _ -> true
335413
336414 foreign import unsafeCompareImpl
337− "function unsafeCompareImpl(lt) {\
338− \ return function(eq) {\
339− \ return function(gt) {\
340− \ return function(x) {\
341− \ return function(y) {\
342− \ return x < y ? lt : x > y ? gt : eq;\
343− \ };\
344− \ };\
345− \ };\
346− \ };\
347− \}" :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
415+ """
416+ function unsafeCompareImpl(lt) {
417+ return function(eq) {
418+ return function(gt) {
419+ return function(x) {
420+ return function(y) {
421+ return x < y ? lt : x > y ? gt : eq;
422+ };
423+ };
424+ };
425+ };
426+ }
427+ """ :: forall a. Ordering -> Ordering -> Ordering -> a -> a -> Ordering
348428
349429 unsafeCompare :: forall a. a -> a -> Ordering
350430 unsafeCompare = unsafeCompareImpl LT EQ GT
@@ -385,45 +465,66 @@ module Prelude
385465 zshr :: b -> Number -> b
386466 complement :: b -> b
387467
388− foreign import numShl "function numShl(n1) {\
389− \ return function(n2) {\
390− \ return n1 << n2;\
391− \ };\
392− \}" :: Number -> Number -> Number
393−
394− foreign import numShr "function numShr(n1) {\
395− \ return function(n2) {\
396− \ return n1 >> n2;\
397− \ };\
398− \}" :: Number -> Number -> Number
399−
400− foreign import numZshr "function numZshr(n1) {\
401− \ return function(n2) {\
402− \ return n1 >>> n2;\
403− \ };\
404− \}" :: Number -> Number -> Number
405−
406− foreign import numAnd "function numAnd(n1) {\
407− \ return function(n2) {\
408− \ return n1 & n2;\
409− \ };\
410− \}" :: Number -> Number -> Number
411−
412− foreign import numOr "function numOr(n1) {\
413− \ return function(n2) {\
414− \ return n1 | n2;\
415− \ };\
416− \}" :: Number -> Number -> Number
417−
418− foreign import numXor "function numXor(n1) {\
419− \ return function(n2) {\
420− \ return n1 ^ n2;\
421− \ };\
422− \}" :: Number -> Number -> Number
423−
424− foreign import numComplement "function numComplement(n) {\
425− \ return ~n;\
426− \}" :: Number -> Number
468+ foreign import numShl
469+ """
470+ function numShl(n1) {
471+ return function(n2) {
472+ return n1 << n2;
473+ };
474+ }
475+ """ :: Number -> Number -> Number
476+
477+ foreign import numShr
478+ """
479+ function numShr(n1) {
480+ return function(n2) {
481+ return n1 >> n2;
482+ };
483+ }
484+ """ :: Number -> Number -> Number
485+
486+ foreign import numZshr
487+ """
488+ function numZshr(n1) {
489+ return function(n2) {
490+ return n1 >>> n2;
491+ };
492+ }
493+ """ :: Number -> Number -> Number
494+
495+ foreign import numAnd
496+ """
497+ function numAnd(n1) {
498+ return function(n2) {
499+ return n1 & n2;
500+ };
501+ }
502+ """ :: Number -> Number -> Number
503+
504+ foreign import numOr
505+ """
506+ function numOr(n1) {
507+ return function(n2) {
508+ return n1 | n2;
509+ };
510+ }
511+ """ :: Number -> Number -> Number
512+
513+ foreign import numXor
514+ """
515+ function numXor(n1) {
516+ return function(n2) {
517+ return n1 ^ n2;
518+ };
519+ }
520+ """ :: Number -> Number -> Number
521+
522+ foreign import numComplement
523+ """
524+ function numComplement(n) {
525+ return ~n;
526+ }
527+ """ :: Number -> Number
427528
428529 instance bitsNumber :: Bits Number where
429530 (.&.) = numAnd
@@ -442,21 +543,30 @@ module Prelude
442543 (||) :: b -> b -> b
443544 not :: b -> b
444545
445− foreign import boolAnd "function boolAnd(b1) {\
446− \ return function(b2) {\
447− \ return b1 && b2;\
448− \ };\
449− \}" :: Boolean -> Boolean -> Boolean
450−
451− foreign import boolOr "function boolOr(b1) {\
452− \ return function(b2) {\
453− \ return b1 || b2;\
454− \ };\
455− \}" :: Boolean -> Boolean -> Boolean
456−
457− foreign import boolNot "function boolNot(b) {\
458− \ return !b;\
459− \}" :: Boolean -> Boolean
546+ foreign import boolAnd
547+ """
548+ function boolAnd(b1) {
549+ return function(b2) {
550+ return b1 && b2;
551+ };
552+ }
553+ """ :: Boolean -> Boolean -> Boolean
554+
555+ foreign import boolOr
556+ """
557+ function boolOr(b1) {
558+ return function(b2) {
559+ return b1 || b2;
560+ };
561+ }
562+ """ :: Boolean -> Boolean -> Boolean
563+
564+ foreign import boolNot
565+ """
566+ function boolNot(b) {
567+ return !b;
568+ }
569+ """ :: Boolean -> Boolean
460570
461571 instance boolLikeBoolean :: BoolLike Boolean where
462572 (&&) = boolAnd
@@ -469,11 +579,13 @@ module Prelude
469579 (<>) :: a -> a -> a
470580
471581 foreign import concatString
472− "function concatString(s1) {\
473− \ return function(s2) {\
474− \ return s1 + s2;\
475− \ };\
476− \}" :: String -> String -> String
582+ """
583+ function concatString(s1) {
584+ return function(s2) {
585+ return s1 + s2;
586+ };
587+ }
588+ """ :: String -> String -> String
477589
478590 instance semigroupUnit :: Semigroup Unit where
479591 (<>) (Unit {}) (Unit {}) = Unit {}
@@ -507,293 +619,334 @@ module Data.Function where
507619 foreign import data Fn10 :: * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> * -> *
508620
509621 foreign import mkFn0
510− "function mkFn0(fn) {\
511− \ return function() {\
512− \ return fn({});\
513− \ };\
514− \}" :: forall a. (Unit -> a) -> Fn0 a
622+ """
623+ function mkFn0(fn) {
624+ return function() {
625+ return fn({});
626+ };
627+ }
628+ """ :: forall a. (Unit -> a) -> Fn0 a
515629
516630 foreign import mkFn1
517− "function mkFn1(fn) {\
518− \ return function(a) {\
519− \ return fn(a);\
520− \ };\
521− \}" :: forall a b. (a -> b) -> Fn1 a b
631+ """
632+ function mkFn1(fn) {
633+ return function(a) {
634+ return fn(a);
635+ };
636+ }
637+ """ :: forall a b. (a -> b) -> Fn1 a b
522638
523639 foreign import mkFn2
524− "function mkFn2(fn) {\
525− \ return function(a, b) {\
526− \ return fn(a)(b);\
527− \ };\
528− \}" :: forall a b c. (a -> b -> c) -> Fn2 a b c
640+ """
641+ function mkFn2(fn) {
642+ return function(a, b) {
643+ return fn(a)(b);
644+ };
645+ }
646+ """ :: forall a b c. (a -> b -> c) -> Fn2 a b c
529647
530648 foreign import mkFn3
531− "function mkFn3(fn) {\
532− \ return function(a, b, c) {\
533− \ return fn(a)(b)(c);\
534− \ };\
535− \}" :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
649+ """
650+ function mkFn3(fn) {
651+ return function(a, b, c) {
652+ return fn(a)(b)(c);
653+ };
654+ }
655+ """ :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d
536656
537657 foreign import mkFn4
538− "function mkFn4(fn) {\
539− \ return function(a, b, c, d) {\
540− \ return fn(a)(b)(c)(d);\
541− \ };\
542− \}" :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
658+ """
659+ function mkFn4(fn) {
660+ return function(a, b, c, d) {
661+ return fn(a)(b)(c)(d);
662+ };
663+ }
664+ """ :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
543665
544666 foreign import mkFn5
545− "function mkFn5(fn) {\
546− \ return function(a, b, c, d, e) {\
547− \ return fn(a)(b)(c)(d)(e);\
548− \ };\
549− \}" :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
667+ """
668+ function mkFn5(fn) {
669+ return function(a, b, c, d, e) {
670+ return fn(a)(b)(c)(d)(e);
671+ };
672+ }
673+ """ :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
550674
551675 foreign import mkFn6
552− "function mkFn6(fn) {\
553− \ return function(a, b, c, d, e, f) {\
554− \ return fn(a)(b)(c)(d)(e)(f);\
555− \ };\
556− \}" :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
676+ """
677+ function mkFn6(fn) {
678+ return function(a, b, c, d, e, f) {
679+ return fn(a)(b)(c)(d)(e)(f);
680+ };
681+ }
682+ """ :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
557683
558684 foreign import mkFn7
559− "function mkFn7(fn) {\
560− \ return function(a, b, c, d, e, f, g) {\
561− \ return fn(a)(b)(c)(d)(e)(f)(g);\
562− \ };\
563− \}" :: 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
685+ """
686+ function mkFn7(fn) {
687+ return function(a, b, c, d, e, f, g) {
688+ return fn(a)(b)(c)(d)(e)(f)(g);
689+ };
690+ }
691+ """ :: 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
564692
565693 foreign import mkFn8
566− "function mkFn8(fn) {\
567− \ return function(a, b, c, d, e, f, g, h) {\
568− \ return fn(a)(b)(c)(d)(e)(f)(g)(h);\
569− \ };\
570− \}" :: 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
694+ """
695+ function mkFn8(fn) {
696+ return function(a, b, c, d, e, f, g, h) {
697+ return fn(a)(b)(c)(d)(e)(f)(g)(h);
698+ };
699+ }
700+ """ :: 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
571701
572702 foreign import mkFn9
573− "function mkFn9(fn) {\
574− \ return function(a, b, c, d, e, f, g, h, i) {\
575− \ return fn(a)(b)(c)(d)(e)(f)(g)(h)(i);\
576− \ };\
577− \}" :: 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
703+ """
704+ function mkFn9(fn) {
705+ return function(a, b, c, d, e, f, g, h, i) {
706+ return fn(a)(b)(c)(d)(e)(f)(g)(h)(i);
707+ };
708+ }
709+ """ :: 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
578710
579711 foreign import mkFn10
580− "function mkFn10(fn) {\
581− \ return function(a, b, c, d, e, f, g, h, i, j) {\
582− \ return fn(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);\
583− \ };\
584− \}" :: 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
712+ """
713+ function mkFn10(fn) {
714+ return function(a, b, c, d, e, f, g, h, i, j) {
715+ return fn(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);
716+ };
717+ }
718+ """ :: 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
585719
586720 foreign import runFn0
587− "function runFn0(fn) {\
588− \ return fn();\
589− \}" :: forall a. Fn0 a -> a
721+ """
722+ function runFn0(fn) {
723+ return fn();
724+ }
725+ """ :: forall a. Fn0 a -> a
590726
591727 foreign import runFn1
592− "function runFn1(fn) {\
593− \ return function(a) {\
594− \ return fn(a);\
595− \ };\
596− \}" :: forall a b. Fn1 a b -> a -> b
728+ """
729+ function runFn1(fn) {
730+ return function(a) {
731+ return fn(a);
732+ };
733+ }
734+ """ :: forall a b. Fn1 a b -> a -> b
597735
598736 foreign import runFn2
599− "function runFn2(fn) {\
600− \ return function(a) {\
601− \ return function(b) {\
602− \ return fn(a, b);\
603− \ };\
604− \ };\
605− \}" :: forall a b c. Fn2 a b c -> a -> b -> c
737+ """
738+ function runFn2(fn) {
739+ return function(a) {
740+ return function(b) {
741+ return fn(a, b);
742+ };
743+ };
744+ }
745+ """ :: forall a b c. Fn2 a b c -> a -> b -> c
606746
607747 foreign import runFn3
608− "function runFn3(fn) {\
609− \ return function(a) {\
610− \ return function(b) {\
611− \ return function(c) {\
612− \ return fn(a, b, c);\
613− \ };\
614− \ };\
615− \ };\
616− \}" :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
748+ """
749+ function runFn3(fn) {
750+ return function(a) {
751+ return function(b) {
752+ return function(c) {
753+ return fn(a, b, c);
754+ };
755+ };
756+ };
757+ }
758+ """ :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d
617759
618760 foreign import runFn4
619− "function runFn4(fn) {\
620− \ return function(a) {\
621− \ return function(b) {\
622− \ return function(c) {\
623− \ return function(d) {\
624− \ return fn(a, b, c, d);\
625− \ };\
626− \ };\
627− \ };\
628− \ };\
629− \}" :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
761+ """
762+ function runFn4(fn) {
763+ return function(a) {
764+ return function(b) {
765+ return function(c) {
766+ return function(d) {
767+ return fn(a, b, c, d);
768+ };
769+ };
770+ };
771+ };
772+ }
773+ """ :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
630774
631775 foreign import runFn5
632− "function runFn5(fn) {\
633− \ return function(a) {\
634− \ return function(b) {\
635− \ return function(c) {\
636− \ return function(d) {\
637− \ return function(e) {\
638− \ return fn(a, b, c, d, e);\
639− \ };\
640− \ };\
641− \ };\
642− \ };\
643− \ };\
644− \}" :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
776+ """
777+ function runFn5(fn) {
778+ return function(a) {
779+ return function(b) {
780+ return function(c) {
781+ return function(d) {
782+ return function(e) {
783+ return fn(a, b, c, d, e);
784+ };
785+ };
786+ };
787+ };
788+ };
789+ }
790+ """ :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
645791
646792 foreign import runFn6
647− "function runFn6(fn) {\
648− \ return function(a) {\
649− \ return function(b) {\
650− \ return function(c) {\
651− \ return function(d) {\
652− \ return function(e) {\
653− \ return function(f) {\
654− \ return fn(a, b, c, d, e, f);\
655− \ };\
656− \ };\
657− \ };\
658− \ };\
659− \ };\
660− \ };\
661− \}" :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
793+ """
794+ function runFn6(fn) {
795+ return function(a) {
796+ return function(b) {
797+ return function(c) {
798+ return function(d) {
799+ return function(e) {
800+ return function(f) {
801+ return fn(a, b, c, d, e, f);
802+ };
803+ };
804+ };
805+ };
806+ };
807+ };
808+ }
809+ """ :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
662810
663811 foreign import runFn7
664− "function runFn7(fn) {\
665− \ return function(a) {\
666− \ return function(b) {\
667− \ return function(c) {\
668− \ return function(d) {\
669− \ return function(e) {\
670− \ return function(f) {\
671− \ return function(g) {\
672− \ return fn(a, b, c, d, e, f, g);\
673− \ };\
674− \ };\
675− \ };\
676− \ };\
677− \ };\
678− \ };\
679− \ };\
680− \}" :: 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
812+ """
813+ function runFn7(fn) {
814+ return function(a) {
815+ return function(b) {
816+ return function(c) {
817+ return function(d) {
818+ return function(e) {
819+ return function(f) {
820+ return function(g) {
821+ return fn(a, b, c, d, e, f, g);
822+ };
823+ };
824+ };
825+ };
826+ };
827+ };
828+ };
829+ }
830+ """ :: 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
681831
682832 foreign import runFn8
683− "function runFn8(fn) {\
684− \ return function(a) {\
685− \ return function(b) {\
686− \ return function(c) {\
687− \ return function(d) {\
688− \ return function(e) {\
689− \ return function(f) {\
690− \ return function(g) {\
691− \ return function(h) {\
692− \ return fn(a, b, c, d, e, f, g, h);\
693− \ };\
694− \ };\
695− \ };\
696− \ };\
697− \ };\
698− \ };\
699− \ };\
700− \ };\
701− \}" :: 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
833+ """
834+ function runFn8(fn) {
835+ return function(a) {
836+ return function(b) {
837+ return function(c) {
838+ return function(d) {
839+ return function(e) {
840+ return function(f) {
841+ return function(g) {
842+ return function(h) {
843+ return fn(a, b, c, d, e, f, g, h);
844+ };
845+ };
846+ };
847+ };
848+ };
849+ };
850+ };
851+ };
852+ }
853+ """ :: 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
702854
703855 foreign import runFn9
704− "function runFn9(fn) {\
705− \ return function(a) {\
706− \ return function(b) {\
707− \ return function(c) {\
708− \ return function(d) {\
709− \ return function(e) {\
710− \ return function(f) {\
711− \ return function(g) {\
712− \ return function(h) {\
713− \ return function(i) {\
714− \ return fn(a, b, c, d, e, f, g, h, i);\
715− \ };\
716− \ };\
717− \ };\
718− \ };\
719− \ };\
720− \ };\
721− \ };\
722− \ };\
723− \ };\
724− \}" :: 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
856+ """
857+ function runFn9(fn) {
858+ return function(a) {
859+ return function(b) {
860+ return function(c) {
861+ return function(d) {
862+ return function(e) {
863+ return function(f) {
864+ return function(g) {
865+ return function(h) {
866+ return function(i) {
867+ return fn(a, b, c, d, e, f, g, h, i);
868+ };
869+ };
870+ };
871+ };
872+ };
873+ };
874+ };
875+ };
876+ };
877+ }
878+ """ :: 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
725879
726880 foreign import runFn10
727− "function runFn10(fn) {\
728− \ return function(a) {\
729− \ return function(b) {\
730− \ return function(c) {\
731− \ return function(d) {\
732− \ return function(e) {\
733− \ return function(f) {\
734− \ return function(g) {\
735− \ return function(h) {\
736− \ return function(i) {\
737− \ return function(j) {\
738− \ return fn(a, b, c, d, e, f, g, h, i, j);\
739− \ };\
740− \ };\
741− \ };\
742− \ };\
743− \ };\
744− \ };\
745− \ };\
746− \ };\
747− \ };\
748− \ };\
749− \}" :: 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
750−
751−module Data.Eq where
752−
753− newtype Ref a = Ref a
754−
755− liftRef :: forall a b. (a -> a -> b) -> Ref a -> Ref a -> b
756− liftRef f (Ref x) (Ref y) = f x y
757−
758− instance eqRef :: Eq (Ref a) where
759− (==) = liftRef refEq
760− (/=) = liftRef refIneq
761−
762− instance functorRef :: Functor Ref where
763− (<$>) f (Ref x) = Ref (f x)
881+ """
882+ function runFn10(fn) {
883+ return function(a) {
884+ return function(b) {
885+ return function(c) {
886+ return function(d) {
887+ return function(e) {
888+ return function(f) {
889+ return function(g) {
890+ return function(h) {
891+ return function(i) {
892+ return function(j) {
893+ return fn(a, b, c, d, e, f, g, h, i, j);
894+ };
895+ };
896+ };
897+ };
898+ };
899+ };
900+ };
901+ };
902+ };
903+ };
904+ }
905+ """ :: 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
764906
765907module Prelude.Unsafe where
766908
767909 foreign import unsafeIndex
768− "function unsafeIndex(xs) {\
769− \ return function(n) {\
770− \ return xs[n];\
771− \ };\
772− \}" :: forall a. [a] -> Number -> a
910+ """
911+ function unsafeIndex(xs) {
912+ return function(n) {
913+ return xs[n];
914+ };
915+ }
916+ """ :: forall a. [a] -> Number -> a
773917
774918module Control.Monad.Eff where
775919
776920 foreign import data Eff :: # ! -> * -> *
777921
778− foreign import returnE "function returnE(a) {\
779− \ return function() {\
780− \ return a;\
781− \ };\
782− \}" :: forall e a. a -> Eff e a
783−
784− foreign import bindE "function bindE(a) {\
785− \ return function(f) {\
786− \ return function() {\
787− \ return f(a())();\
788− \ };\
789− \ };\
790− \}" :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
922+ foreign import returnE
923+ """
924+ function returnE(a) {
925+ return function() {
926+ return a;
927+ };
928+ }
929+ """ :: forall e a. a -> Eff e a
930+
931+ foreign import bindE
932+ """
933+ function bindE(a) {
934+ return function(f) {
935+ return function() {
936+ return f(a())();
937+ };
938+ };
939+ }
940+ """ :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
791941
792942 type Pure a = forall e. Eff e a
793943
794− foreign import runPure "function runPure(f) {\
795− \ return f();\
796− \}" :: forall a. Pure a -> a
944+ foreign import runPure
945+ """
946+ function runPure(f) {
947+ return f();
948+ }
949+ """ :: forall a. Pure a -> a
797950
798951 instance functorEff :: Functor (Eff e) where
799952 (<$>) = liftA1
@@ -809,55 +962,69 @@ module Control.Monad.Eff where
809962
810963 instance monadEff :: Monad (Eff e)
811964
812− foreign import untilE "function untilE(f) {\
813− \ return function() {\
814− \ while (!f());\
815− \ return {};\
816− \ };\
817− \}" :: forall e. Eff e Boolean -> Eff e Unit
818−
819− foreign import whileE "function whileE(f) {\
820− \ return function(a) {\
821− \ return function() {\
822− \ while (f()) {\
823− \ a();\
824− \ }\
825− \ return {};\
826− \ };\
827− \ };\
828− \}" :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
829−
830− foreign import forE "function forE(lo) {\
831− \ return function(hi) {\
832− \ return function(f) {\
833− \ return function() {\
834− \ for (var i = lo; i < hi; i++) {\
835− \ f(i)();\
836− \ }\
837− \ };\
838− \ };\
839− \ };\
840− \}" :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
841−
842−
843− foreign import foreachE "function foreachE(as) {\
844− \ return function(f) {\
845− \ return function() {\
846− \ for (var i = 0; i < as.length; i++) {\
847− \ f(as[i])();\
848− \ }\
849− \ };\
850− \ };\
851− \}" :: forall e a. [a] -> (a -> Eff e Unit) -> Eff e Unit
965+ foreign import untilE
966+ """
967+ function untilE(f) {
968+ return function() {
969+ while (!f());
970+ return {};
971+ };
972+ }
973+ """ :: forall e. Eff e Boolean -> Eff e Unit
974+
975+ foreign import whileE
976+ """
977+ function whileE(f) {
978+ return function(a) {
979+ return function() {
980+ while (f()) {
981+ a();
982+ }
983+ return {};
984+ };
985+ };
986+ }
987+ """ :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
988+
989+ foreign import forE
990+ """
991+ function forE(lo) {
992+ return function(hi) {
993+ return function(f) {
994+ return function() {
995+ for (var i = lo; i < hi; i++) {
996+ f(i)();
997+ }
998+ };
999+ };
1000+ };
1001+ }
1002+ """ :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
1003+
1004+
1005+ foreign import foreachE
1006+ """
1007+ function foreachE(as) {
1008+ return function(f) {
1009+ return function() {
1010+ for (var i = 0; i < as.length; i++) {
1011+ f(as[i])();
1012+ }
1013+ };
1014+ };
1015+ }
1016+ """ :: forall e a. [a] -> (a -> Eff e Unit) -> Eff e Unit
8521017
8531018module Control.Monad.Eff.Unsafe where
8541019
8551020 import Control.Monad.Eff
8561021
8571022 foreign import unsafeInterleaveEff
858− "function unsafeInterleaveEff(f) {\
859− \ return f;\
860− \}" :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
1023+ """
1024+ function unsafeInterleaveEff(f) {
1025+ return f;
1026+ }
1027+ """ :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
8611028
8621029module Debug.Trace where
8631030
@@ -865,12 +1032,15 @@ module Debug.Trace where
8651032
8661033 foreign import data Trace :: !
8671034
868− foreign import trace "function trace(s) {\
869− \ return function() {\
870− \ console.log(s);\
871− \ return {};\
872− \ };\
873− \}" :: forall r. String -> Eff (trace :: Trace | r) Unit
1035+ foreign import trace
1036+ """
1037+ function trace(s) {
1038+ return function() {
1039+ console.log(s);
1040+ return {};
1041+ };
1042+ }
1043+ """ :: forall r. String -> Eff (trace :: Trace | r) Unit
8741044
8751045 print :: forall a r. (Show a) => a -> Eff (trace :: Trace | r) Unit
8761046 print o = trace (show o)
@@ -883,37 +1053,52 @@ module Control.Monad.ST where
8831053
8841054 foreign import data STRef :: * -> * -> *
8851055
886− foreign import newSTRef "function newSTRef(val) {\
887− \ return function() {\
888− \ return { value: val };\
889− \ };\
890− \}" :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
891−
892− foreign import readSTRef "function readSTRef(ref) {\
893− \ return function() {\
894− \ return ref.value;\
895− \ };\
896− \}" :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
897−
898− foreign import modifySTRef "function modifySTRef(ref) {\
899− \ return function(f) {\
900− \ return function() {\
901− \ return ref.value = f(ref.value);\
902− \ };\
903− \ };\
904− \}" :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
905−
906− foreign import writeSTRef "function writeSTRef(ref) {\
907− \ return function(a) {\
908− \ return function() {\
909− \ return ref.value = a;\
910− \ };\
911− \ };\
912− \}" :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
913−
914− foreign import runST "function runST(f) {\
915− \ return f;\
916− \}" :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
1056+ foreign import newSTRef
1057+ """
1058+ function newSTRef(val) {
1059+ return function() {
1060+ return { value: val };
1061+ };
1062+ }
1063+ """ :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
1064+
1065+ foreign import readSTRef
1066+ """
1067+ function readSTRef(ref) {
1068+ return function() {
1069+ return ref.value;
1070+ };
1071+ }
1072+ """ :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
1073+
1074+ foreign import modifySTRef
1075+ """
1076+ function modifySTRef(ref) {
1077+ return function(f) {
1078+ return function() {
1079+ return ref.value = f(ref.value);
1080+ };
1081+ };
1082+ }
1083+ """ :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
1084+
1085+ foreign import writeSTRef
1086+ """
1087+ function writeSTRef(ref) {
1088+ return function(a) {
1089+ return function() {
1090+ return ref.value = a;
1091+ };
1092+ };
1093+ }
1094+ """ :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
1095+
1096+ foreign import runST
1097+ """
1098+ function runST(f) {
1099+ return f;
1100+ }
1101+ """ :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
9171102
9181103 pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
9191104 pureST st = runPure (runST st)