@@ -909,19 +909,19 @@ module Math where
909909 \}" :: Number -> Number
910910
911911 foreign import max "function max(n1){\
912− \ return function(n2) {\
912+ \ return function(n2) {\
913913 \ return Math.max(n1, n2);\
914914 \ }\
915915 \}" :: Number -> Number -> Number
916916
917917 foreign import min "function min(n1){\
918− \ return function(n2) {\
918+ \ return function(n2) {\
919919 \ return Math.min(n1, n2);\
920920 \ }\
921921 \}" :: Number -> Number -> Number
922922
923923 foreign import pow "function pow(n){\
924− \ return function(p) {\
924+ \ return function(p) {\
925925 \ return Math.pow(n, p);\
926926 \ }\
927927 \}" :: Number -> Number -> Number
@@ -1206,7 +1206,7 @@ module Data.Enum where
12061206 class Enum a where
12071207 toEnum :: Number -> Maybe a
12081208 fromEnum :: a -> Number
1209−
1209+
12101210module Text.Parsing.Read where
12111211
12121212 class Read a where
@@ -1223,3 +1223,61 @@ module Text.Parsing.Read where
12231223
12241224 instance readNumber :: Read Number where
12251225 read = readNumberImpl
1226+
1227+module Data.Foldable where
1228+
1229+ import Prelude
1230+ import Data.Either
1231+ import Data.Eq
1232+ import Data.Maybe
1233+ import Data.Monoid
1234+ import Data.Tuple
1235+
1236+ class Foldable f where
1237+ foldr :: forall a b. (a -> b -> b) -> b -> f a -> b
1238+ foldl :: forall a b. (b -> a -> b) -> b -> f a -> b
1239+ foldMap :: forall a m. (Monoid m) => (a -> m) -> f a -> m
1240+
1241+ instance foldableArray :: Foldable [] where
1242+ foldr _ z [] = z
1243+ foldr f z (x:xs) = x `f` (foldr f z xs)
1244+
1245+ foldl _ z [] = z
1246+ foldl f z (x:xs) = foldl f (z `f` x) xs
1247+
1248+ foldMap _ [] = mempty
1249+ foldMap f (x:xs) = f x <> foldMap f xs
1250+
1251+ instance foldableEither :: Foldable (Either a) where
1252+ foldr _ z (Left _) = z
1253+ foldr f z (Right x) = x `f` z
1254+
1255+ foldl _ z (Left _) = z
1256+ foldl f z (Right x) = z `f` x
1257+
1258+ foldMap f (Left _) = mempty
1259+ foldMap f (Right x) = f x
1260+
1261+ instance foldableMaybe :: Foldable Maybe where
1262+ foldr _ z Nothing = z
1263+ foldr f z (Just x) = x `f` z
1264+
1265+ foldl _ z Nothing = z
1266+ foldl f z (Just x) = z `f` x
1267+
1268+ foldMap f Nothing = mempty
1269+ foldMap f (Just x) = f x
1270+
1271+ instance foldableRef :: Foldable Ref where
1272+ foldr f z (Ref x) = x `f` z
1273+
1274+ foldl f z (Ref x) = z `f` x
1275+
1276+ foldMap f (Ref x) = f x
1277+
1278+ instance foldableTuple :: Foldable (Tuple a) where
1279+ foldr f z (Tuple _ x) = x `f` z
1280+
1281+ foldl f z (Tuple _ x) = z `f` x
1282+
1283+ foldMap f (Tuple _ x) = f x