@@ -49,8 +49,9 @@ module Maybe where
49 fromMaybe :: forall a. a -> Maybe a -> a
49 fromMaybe :: forall a. a -> Maybe a -> a
50 fromMaybe a = maybe a Prelude.id
50 fromMaybe a = maybe a Prelude.id
52− bindMaybe :: forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
52+ instance Prelude.Monad Maybe where
53− bindMaybe m f = maybe Nothing f m
54+ (>>=) m f = maybe Nothing f m
55module Either where
56module Either where
@@ -60,11 +61,13 @@ module Either where
60 either f _ (Left a) = f a
61 either f _ (Left a) = f a
61 either _ g (Right b) = g b
62 either _ g (Right b) = g b
63− bindEither :: forall e a b. Either e a -> (a -> Either e b) -> Either e b
64+ instance Prelude.Monad (Either e) where
64− bindEither = either (\e _ -> Left e) (\a f -> f a)
66+ (>>=) = either (\e _ -> Left e) (\a f -> f a)
66module Arrays where
68module Arrays where
68 import Maybe
71 import Maybe
70 head :: forall a. [a] -> a
73 head :: forall a. [a] -> a
@@ -97,27 +100,77 @@ module Arrays where
97 \ return xs.length; \
100 \ return xs.length; \
98 \}" :: forall a. [a] -> Number
101 \}" :: forall a. [a] -> Number
103+ foreign import indexOf "function indexOf(l) {\
104+ \ return function (e) {\
105+ \ return l.indexOf(e);\
100− foreign import indexOf :: forall a. [a] -> a -> Number
107+ \}" :: forall a. [a] -> a -> Number
102− foreign import lastIndexOf :: forall a. [a] -> a -> Number
109+ foreign import lastIndexOf "function lastIndexOf(l) {\
103−
110+ \ return function (e) {\
111+ \ return l.lastIndexOf(e);\
113+ \}" :: forall a. [a] -> a -> Number
104− foreign import concat :: forall a. [a] -> [a] -> [a]
115+ foreign import concat "function concat(l1) {\
105−
116+ \ return function (l2) {\
117+ \ return l1.concat(l2);\
119+ \}" :: forall a. [a] -> [a] -> [a]
121+ foreign import join "function join(l) {\
106− foreign import join :: [String] -> String
123+ \}" :: [String] -> String
108− foreign import joinWith :: [String] -> String -> String
125+ foreign import joinWith "function joinWith(l) {\
109−
126+ \ return function (s) {\
110− foreign import push :: forall a. [a] -> a -> [a]
127+ \ return l.join(s);\
129+ \}" :: [String] -> String -> String
112− foreign import reverse :: forall a. [a] -> [a]
131+ foreign import push "function push(l) {\
113−
132+ \ return function (e) {\
133+ \ var l1 = l.slice();\
137+ \}" :: forall a. [a] -> a -> [a]
139+ foreign import reverse "function reverse(l) {\
140+ \ var l1 = l.slice();\
143+ \}" :: forall a. [a] -> [a]
145+ foreign import shift "function shift(l) {\
146+ \ var l1 = l.slice();\
114− foreign import shift :: forall a. [a] -> [a]
149+ \}" :: forall a. [a] -> [a]
151+ foreign import slice "function slice(s) {\
152+ \ return function(e) {\
153+ \ return function (l) {\
154+ \ return l.slice(s, e);\
116− foreign import slice :: forall a. Number -> Number -> [a] -> [a]
157+ \}" :: forall a. Number -> Number -> [a] -> [a]
118− foreign import sort :: forall a. [a] -> [a]
159+ foreign import sort "function sort(l) {\
119−
160+ \ var l1 = l.slice();\
163+ \}" :: forall a. [a] -> [a]
165+ foreign import splice "function splice(s) {\
166+ \ return function(e) {\
167+ \ return function(l1) { \
168+ \ return function(l2) {\
169+ \ return l2.splice(s, e, l1);\
120− foreign import splice :: forall a. Number -> Number -> [a] -> [a] -> [a]
173+ \}":: forall a. Number -> Number -> [a] -> [a] -> [a]
122 infixr 6 :
175 infixr 6 :
@@ -158,6 +211,10 @@ module Arrays where
158 all _ [] = true
211 all _ [] = true
159 all p (a:as) = p a && all p as
212 all p (a:as) = p a && all p as
214+ instance (Prelude.Show a) => Prelude.Show [a] where
216+ show (x:xs) = show x ++ " : " ++ show xs
161module Tuple where
218module Tuple where
163 import Arrays
220 import Arrays
@@ -187,57 +244,141 @@ module String where
187 \ return s.length;\
244 \ return s.length;\
188 \}" :: String -> Number
245 \}" :: String -> Number
247+ foreign import charAt "function charAt(i) {\
248+ \ return function(s) {\
249+ \ return s.charAt(i); \
190− foreign import charAt :: Number -> String -> String
251+ \}" :: Number -> String -> String
253+ foreign import indexOfS "function indexOfS(s1) {\
254+ \ return function(s2) {\
255+ \ return s2.indexOf(s2);\
192− foreign import indexOfS :: String -> String -> Number
257+ \}" :: String -> String -> Number
259+ foreign import lastIndexOfS "function lastIndexOfS(s1) {\
260+ \ return function(s2) {\
261+ \ return s2.lastIndexOf(s2);\
194− foreign import lastIndexOfS :: String -> String -> Number
263+ \}" :: String -> String -> Number
265+ foreign import localeCompare "function localeCompare(s1) {\
266+ \ return function(s2) { \
267+ \ return s1.localeCompare(s2);\
196− foreign import localeCompare :: String -> String -> Number
269+ \}" :: String -> String -> Number
271+ foreign import replace "function replace(s1) {\
272+ \ return function(s2) {\
273+ \ return function(s3) {\
274+ \ return s3.replace(s1, s2);\
198− foreign import replace :: String -> String -> String -> String
277+ \}" :: String -> String -> String -> String
279+ foreign import sliceS "function sliceS(st) {\
280+ \ return function(e) {\
281+ \ return function(s) {\
282+ \ return s.slice(st, e);\
200− foreign import sliceS :: Number -> Number -> String -> String
285+ \}" :: Number -> Number -> String -> String
287+ foreign import split "function split(sep) {\
288+ \ return function(s) {\
289+ \ return s.split(s);\
202− foreign import split :: String -> String -> [String]
291+ \}" :: String -> String -> [String]
293+ foreign import substr "function substr(n1) {\
294+ \ return function(n2) {\
295+ \ return function(s) {\
296+ \ return s.substr(n1, n2);\
204− foreign import substr :: Number -> Number -> String -> String
299+ \}" :: Number -> Number -> String -> String
301+ foreign import substring "function substring(n1) {\
302+ \ return function(n2) {\
303+ \ return function(s) {\
304+ \ return s.substring(n1, n2);\
206− foreign import substring :: Number -> Number -> String -> String
307+ \}" :: Number -> Number -> String -> String
208− foreign import toLower :: String -> String
309+ foreign import toLower "function toLower(s) {\
209−
310+ \ return s.toLower();\
311+ \}" :: String -> String
210− foreign import toUpper :: String -> String
313+ foreign import toUpper "function toUpper(s) {\
211−
314+ \ return s.toUpper();\
315+ \}" :: String -> String
317+ foreign import trim "function trim(s) {\
212− foreign import trim :: String -> String
319+ \}" :: String -> String
214module Regex where
321module Regex where
216 foreign import data Regex :: *
323 foreign import data Regex :: *
325+ foreign import regex "function regex(s1) {\
326+ \ return function(s2) {\
327+ \ return new Regex(s1, s2);\
218− foreign import regex :: String -> String -> Regex
329+ \}" :: String -> String -> Regex
331+ foreign import test "function test(r) {\
332+ \ return function (s) { \
333+ \ return r.test(s);\
220− foreign import test :: Regex -> String -> Boolean
335+ \}" :: Regex -> String -> Boolean
337+ foreign import match "function match(r) {\
338+ \ return function (s) {\
339+ \ return s.match(r); \
222− foreign import match :: Regex -> String -> [String]
341+ \}" :: Regex -> String -> [String]
343+ foreign import replaceR "function replaceR(r) {\
344+ \ return function(s1) {\
345+ \ return function(s2) { \
346+ \ return s2.replace(r, s1);\
224− foreign import replaceR :: Regex -> String -> String -> String
349+ \}" :: Regex -> String -> String -> String
351+ foreign import search "function search(r) {\
352+ \ return function (s) {\
353+ \ return s.search(r);\
226− foreign import search :: Regex -> String -> Number
355+ \}" :: Regex -> String -> Number
228module Global where
357module Global where
230− foreign import nan :: Number
359+ foreign import nan "var nan = NaN;" :: Number
232− foreign import infinity :: Number
361+ foreign import infinity "var infinity = Infinity;" :: Number
234− foreign import toExponential :: Number -> String
363+ foreign import toExponential "function toExponential(n) {\
364+ \ return n.toExponential();\
365+ \}" :: Number -> String
367+ foreign import toFixed "function toFixed(d) {\
368+ \ return function(n) {\
369+ \ return n.toFixed(d);\
236− foreign import toFixed :: Number -> Number -> String
371+ \}" :: Number -> Number -> String
373+ foreign import toPrecision "function toPrecision(d) {\
374+ \ return function(n) {\
375+ \ return n.toPrecision(d);\
238− foreign import toPrecision :: Number -> Number -> String
377+ \}" :: Number -> Number -> String
240− foreign import numberToString :: Number -> String
379+ foreign import numberToString "function numberToString(n) {\
380+ \ return n.toString();\
381+ \}" :: Number -> String
242 foreign import isNaN :: Number -> Boolean
383 foreign import isNaN :: Number -> Boolean
@@ -255,6 +396,9 @@ module Global where
256 foreign import decodeURI :: String -> String
397 foreign import decodeURI :: String -> String
399+ instance Prelude.Show Number where
400+ show = numberToString
258module Math where
402module Math where
260 type Math =
404 type Math =
@@ -277,19 +421,31 @@ module Math where
277 , tan :: Number -> Number
421 , tan :: Number -> Number
280− foreign import math :: Math
424+ foreign import math "var math = Math;" :: Math
282module Eff where
426module Eff where
284 foreign import data Eff :: # ! -> * -> *
428 foreign import data Eff :: # ! -> * -> *
286− foreign import retEff "function retEff(a) { return function() { return a; }; }" :: forall e a. a -> Eff e a
430+ foreign import retEff "function retEff(a) { \
431+ \ return function() { \
434+ \}" :: forall e a. a -> Eff e a
288− foreign import bindEff "function bindEff(a) { return function(f) { return function() { return f(a())(); }; }; }" :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
436+ foreign import bindEff "function bindEff(a) { \
437+ \ return function(f) { \
438+ \ return function() { \
439+ \ return f(a())(); \
442+ \}" :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
290 type Pure a = forall e. Eff e a
444 type Pure a = forall e. Eff e a
292− foreign import runPure "function runPure(f) { return f(); }" :: forall a. Pure a -> a
446+ foreign import runPure "function runPure(f) { \
448+ \}" :: forall a. Pure a -> a
294 instance Prelude.Monad (Eff e) where
450 instance Prelude.Monad (Eff e) where
295 ret = retEff
451 ret = retEff
@@ -301,9 +457,23 @@ module Errors where
302 foreign import data Error :: * -> !
458 foreign import data Error :: * -> !
304− foreign import throwError "function throwError(e) { return function() { throw e; }; }" :: forall a e r. e -> Eff (err :: Error e | r) a
460+ foreign import throwError "function throwError(e) { \
305−
461+ \ return function() { \
464+ \}" :: forall a e r. e -> Eff (err :: Error e | r) a
306− foreign import catchError "function catchError(c) { return function(t) { return function() { try { return t(); } catch(e) { return c(e)(); } }; }; }" :: forall e r a. (e -> Eff r a) -> Eff (err :: Error e | r) a -> Eff r a
466+ foreign import catchError "function catchError(c) { \
467+ \ return function(t) { \
468+ \ return function() { \
476+ \}" :: forall e r a. (e -> Eff r a) -> Eff (err :: Error e | r) a -> Eff r a
308module IORef where
478module IORef where
@@ -313,11 +483,25 @@ module IORef where
314 foreign import data IORef :: * -> *
484 foreign import data IORef :: * -> *
486+ foreign import newIORef "function newIORef(val) {\
487+ \ return function () {\
488+ \ return { value: val };\
316− foreign import newIORef :: forall s r. s -> Eff (ref :: Ref | r) (IORef s)
490+ \}" :: forall s r. s -> Eff (ref :: Ref | r) (IORef s)
492+ foreign import readIORef "function readIORef(ref) {\
493+ \ return function() {\
494+ \ return ref.value;\
318− foreign import readIORef :: forall s r. IORef s -> Eff (ref :: Ref | r) s
496+ \}" :: forall s r. IORef s -> Eff (ref :: Ref | r) s
498+ foreign import writeIORef "function writeIORef(ref) {\
499+ \ return function(val) {\
500+ \ return function() {\
320− foreign import writeIORef :: forall s r. IORef s -> s -> Eff (ref :: Ref | r) {}
504+ \}" :: forall s r. IORef s -> s -> Eff (ref :: Ref | r) {}
322module Trace where
506module Trace where
@@ -326,7 +510,12 @@ module Trace where
327 foreign import data Trace :: !
511 foreign import data Trace :: !
329− foreign import trace "function trace(s) { return function() { console.log(s); return {}; }; }" :: forall r. String -> Eff (trace :: Trace | r) {}
513+ foreign import trace "function trace(s) { \
514+ \ return function() { \
518+ \}" :: forall r. String -> Eff (trace :: Trace | r) {}
331 print :: forall a r. (Prelude.Show a) => a -> Eff (trace :: Trace | r) {}
520 print :: forall a r. (Prelude.Show a) => a -> Eff (trace :: Trace | r) {}
332 print o = trace (show o)
521 print o = trace (show o)
@@ -339,11 +528,27 @@ module ST where
340 foreign import data STRef :: * -> * -> *
529 foreign import data STRef :: * -> * -> *
531+ foreign import newSTRef "function newSTRef(val) {\
532+ \ return function () {\
533+ \ return { value: val };\
342− foreign import newSTRef :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
535+ \}" :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
537+ foreign import readSTRef "function readSTRef(ref) {\
538+ \ return function() {\
539+ \ return ref.value;\
344− foreign import readSTRef :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
541+ \}" :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
543+ foreign import modifySTRef "function modifySTRef(f) {\
544+ \ return function(ref) {\
545+ \ return function() {\
546+ \ ref.value = f(ref.value);\
346− foreign import modifySTRef :: forall a h r. (a -> a) -> STRef h a -> Eff (st :: ST h | r) {}
549+ \}" :: forall a h r. (a -> a) -> STRef h a -> Eff (st :: ST h | r) {}
551+ foreign import runST "function runST(f) {\
348− foreign import runST :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
553+ \}" :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a