@@ -54,6 +54,13 @@ module Prelude where
54 instance Read Boolean where
54 instance Read Boolean where
55 read "true" = true
55 read "true" = true
56 read _ = false
56 read _ = false
58+ foreign import readNumber "function readNumber(n) {\
59+ \ return parseInt(n, 10);\
60+ \}" :: String -> Number
62+ instance Read Number where
58 infixl 4 <$>
65 infixl 4 <$>
@@ -362,6 +369,10 @@ module Monoid where
362 instance Monoid String where
369 instance Monoid String where
363 mempty = ""
370 mempty = ""
364 (<>) = (++)
371 (<>) = (++)
373+ instance Monoid [a] where
375+ (<>) = Arrays.concat
366 mconcat :: forall m. (Monoid m) => [m] -> m
377 mconcat :: forall m. (Monoid m) => [m] -> m
367 mconcat [] = mempty
378 mconcat [] = mempty
@@ -429,22 +440,52 @@ module Maybe where
430 fromMaybe :: forall a. a -> Maybe a -> a
441 fromMaybe :: forall a. a -> Maybe a -> a
431 fromMaybe a = maybe a (Prelude.id :: forall a. a -> a)
442 fromMaybe a = maybe a (Prelude.id :: forall a. a -> a)
444+ instance Prelude.Functor Maybe where
445+ (<$>) fn (Just x) = Just (fn x)
448+ instance Prelude.Applicative Maybe where
450+ (<*>) (Just fn) x = fn <$> x
451+ (<*>) Nothing _ = Nothing
433 instance Prelude.Monad Maybe where
453 instance Prelude.Monad Maybe where
434 return = Just
454 return = Just
435 (>>=) m f = maybe Nothing f m
455 (>>=) m f = maybe Nothing f m
457+ instance (Show a) => Prelude.Show (Maybe a) where
458+ show (Just x) = "Just " ++ (show x)
459+ show Nothing = "Nothing"
437module Either where
461module Either where
439 data Either a b = Left a | Right b
465 data Either a b = Left a | Right b
441 either :: forall a b c. (a -> c) -> (b -> c) -> Either a b -> c
467 either :: forall a b c. (a -> c) -> (b -> c) -> Either a b -> c
442 either f _ (Left a) = f a
468 either f _ (Left a) = f a
443 either _ g (Right b) = g b
469 either _ g (Right b) = g b
472+ instance Prelude.Functor (Either a) where
473+ (<$>) _ (Left x) = Left x
474+ (<$>) f (Right y) = Right (f y)
477+ instance Prelude.Applicative (Either e) where
479+ (<*>) (Left e) _ = Left e
480+ (<*>) (Right f) r = f <$> r
445 instance Prelude.Monad (Either e) where
482 instance Prelude.Monad (Either e) where
446 return = Right
483 return = Right
447 (>>=) = either (\e _ -> Left e) (\a f -> f a)
484 (>>=) = either (\e _ -> Left e) (\a f -> f a)
486+ instance (Show a, Show b) => Prelude.Show (Either a b) where
487+ show (Left x) = "Left " ++ (show x)
488+ show (Right y) = "Right " ++ (show y)
449module Arrays where
490module Arrays where
@@ -578,7 +619,7 @@ module Arrays where
578 range lo hi = {
619 range lo hi = {
579 var ns = [];
620 var ns = [];
580 for (n <- lo until hi) {
621 for (n <- lo until hi) {
581− ns = push ns n;
622+ ns = push ns n;
583 return ns;
624 return ns;
@@ -598,7 +639,10 @@ module Arrays where
598 instance (Prelude.Show a) => Prelude.Show [a] where
639 instance (Prelude.Show a) => Prelude.Show [a] where
599 show [] = "[]"
640 show [] = "[]"
600 show (x:xs) = show x ++ " : " ++ show xs
641 show (x:xs) = show x ++ " : " ++ show xs
643+ instance Prelude.Functor [] where
602 instance Prelude.Monad [] where
646 instance Prelude.Monad [] where
603 return = singleton
647 return = singleton
604 (>>=) = concatMap
648 (>>=) = concatMap