air 2012.5.15 → 2013.6.22
raw patch · 3 files changed
+37/−63 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Air.Light: apply, send_to :: a -> (a -> b) -> b
- Air.Light: eq, aren't, isn't, is_not, is :: Eq a => a -> a -> Bool
- Air.Light: first, fifth, forth, third, second :: Show a => [a] -> a
- Air.Light: first_or :: a -> [a] -> a
- Air.Light: inject, inject' :: Foldable t => a -> (a -> b -> a) -> t b -> a
- Air.Light: inner_inject :: Foldable t => a -> (a -> b -> a) -> [t b] -> [a]
- Air.Light: inner_map :: (a -> b) -> [[a]] -> [[b]]
- Air.Light: inner_reduce :: (a -> a -> a) -> [[a]] -> [a]
- Air.Light: insert_at, replace_at :: Integral i => i -> a -> [a] -> [a]
- Air.Light: join' :: [[a]] -> [a]
- Air.Light: ljust, rjust :: Integral i => i -> a -> [a] -> [a]
- Air.Light: lower, upper :: String -> String
- Air.Light: none_of :: (a -> Bool) -> [a] -> Bool
- Air.Light: only_fst :: [(a, b)] -> [a]
- Air.Light: only_snd :: [(a, b)] -> [b]
- Air.Light: reduce, reduce' :: (a -> a -> a) -> [a] -> a
- Air.Light: select, reject :: (a -> Bool) -> [a] -> [a]
- Air.Light: sixth, tenth, ninth, eighth, seventh :: Show a => [a] -> a
- Air.Light: squeeze :: Monad m => m (m a) -> m a
- Air.Light: starts_with, ends_with :: String -> String -> Bool
- Air.Light: twin :: a -> (a, a)
- Air.SimpleMath: decode :: [(Int, a)] -> [a]
- Air.SimpleMath: encode :: Eq a => [a] -> [(Int, a)]
+ Air.Light: ap2 :: Applicative f => (a1 -> a -> b) -> f a1 -> f a -> f b
+ Air.Light: ap3 :: Applicative f => (a2 -> a1 -> a -> b) -> f a2 -> f a1 -> f a -> f b
+ Air.Light: ap4 :: Applicative f => (a3 -> a2 -> a1 -> a -> b) -> f a3 -> f a2 -> f a1 -> f a -> f b
+ Air.Light: ap5 :: Applicative f => (a4 -> a3 -> a2 -> a1 -> a -> b) -> f a4 -> f a3 -> f a2 -> f a1 -> f a -> f b
+ Air.Light: ap6 :: Applicative f => (a5 -> a4 -> a3 -> a2 -> a1 -> a -> b) -> f a5 -> f a4 -> f a3 -> f a2 -> f a1 -> f a -> f b
+ Air.Light: ap7 :: Applicative f => (a6 -> a5 -> a4 -> a3 -> a2 -> a1 -> a -> b) -> f a6 -> f a5 -> f a4 -> f a3 -> f a2 -> f a1 -> f a -> f b
+ Air.Light: ap8 :: Applicative f => (a7 -> a6 -> a5 -> a4 -> a3 -> a2 -> a1 -> a -> b) -> f a7 -> f a6 -> f a5 -> f a4 -> f a3 -> f a2 -> f a1 -> f a -> f b
+ Air.Light: ap9 :: Applicative f => (a8 -> a7 -> a6 -> a5 -> a4 -> a3 -> a2 -> a1 -> a -> b) -> f a8 -> f a7 -> f a6 -> f a5 -> f a4 -> f a3 -> f a2 -> f a1 -> f a -> f b
+ Air.Light: aren't :: Eq a => a -> a -> Bool
+ Air.Light: clone :: a -> (a, a)
+ Air.Light: eighth :: [a] -> Maybe a
+ Air.Light: ends_with :: String -> String -> Bool
+ Air.Light: eq :: Eq a => a -> a -> Bool
+ Air.Light: fifth :: [a] -> Maybe a
+ Air.Light: first :: [a] -> Maybe a
+ Air.Light: forth :: [a] -> Maybe a
+ Air.Light: inject :: Foldable t => a -> (a -> b -> a) -> t b -> a
+ Air.Light: inject' :: Foldable t => a -> (a -> b -> a) -> t b -> a
+ Air.Light: insert_at :: Integral i => i -> a -> [a] -> [a]
+ Air.Light: is :: Eq a => a -> a -> Bool
+ Air.Light: is_not :: Eq a => a -> a -> Bool
+ Air.Light: isn't :: Eq a => a -> a -> Bool
+ Air.Light: ljust :: Integral i => i -> a -> [a] -> [a]
+ Air.Light: lower :: String -> String
+ Air.Light: ninth :: [a] -> Maybe a
+ Air.Light: reduce :: (a -> a -> a) -> [a] -> a
+ Air.Light: reduce' :: (a -> a -> a) -> [a] -> a
+ Air.Light: reject :: (a -> Bool) -> [a] -> [a]
+ Air.Light: replace_at :: Integral i => i -> a -> [a] -> [a]
+ Air.Light: rjust :: Integral i => i -> a -> [a] -> [a]
+ Air.Light: second :: [a] -> Maybe a
+ Air.Light: select :: (a -> Bool) -> [a] -> [a]
+ Air.Light: seventh :: [a] -> Maybe a
+ Air.Light: sixth :: [a] -> Maybe a
+ Air.Light: starts_with :: String -> String -> Bool
+ Air.Light: tenth :: [a] -> Maybe a
+ Air.Light: third :: [a] -> Maybe a
+ Air.Light: upper :: String -> String
- Air.Light: (!!) :: Integral a => [b] -> a -> b
+ Air.Light: (!!) :: Integral a => [b] -> a -> Maybe b
- Air.Light: at :: (Show a, Integral i, Show i) => i -> [a] -> a
+ Air.Light: at :: Integral i => i -> [a] -> Maybe a
- Air.Light: cherry_pick :: Integral i => [i] -> [a] -> [a]
+ Air.Light: cherry_pick :: Integral i => [i] -> [a] -> [Maybe a]
- Air.Light: tuple2 :: Show a => [a] -> (a, a)
+ Air.Light: tuple2 :: [a] -> Maybe (a, a)
- Air.Light: tuple3 :: Show a => [a] -> (a, a, a)
+ Air.Light: tuple3 :: Show a => [a] -> Maybe (a, a, a)
Files
- air.cabal +1/−1
- src/Air/Light.hs +36/−55
- src/Air/SimpleMath.hs +0/−7
air.cabal view
@@ -1,5 +1,5 @@ Name: air-Version: 2012.5.15+Version: 2013.6.22 Build-type: Simple Synopsis: air Description: An alternative Haskell Prelude library.
src/Air/Light.hs view
@@ -21,8 +21,11 @@ import Control.Concurrent import System.Exit ( exitWith, ExitCode(ExitSuccess) ) +import Control.Applicative ((<$>), (<*>))+ import qualified Data.ByteString.Lazy.Char8 as LazyByteString import qualified Data.ByteString.Char8 as StrictByteString+import Data.Maybe (listToMaybe) -- base DSL@@ -61,12 +64,12 @@ join :: [a] -> [[a]] -> [a] join = L.intercalate -join' :: [[a]] -> [a]-join' = concat+at :: (Integral i) => i -> [a] -> Maybe a+at i xs = xs.drop i.first -first, second, third, forth, fifth :: (Show a) => [a] -> a-sixth, seventh, eighth, ninth, tenth :: (Show a) => [a] -> a-first = head+first, second, third, forth, fifth :: [a] -> Maybe a+sixth, seventh, eighth, ninth, tenth :: [a] -> Maybe a+first = listToMaybe second = at 1 third = at 2 forth = at 3@@ -108,8 +111,8 @@ slice :: (Integral i) => i -> i -> [a] -> [a] slice l r = take r > drop l -cherry_pick :: (Integral i) => [i] -> [a] -> [a]-cherry_pick ids xs = ids.map(xs !!)+cherry_pick :: (Integral i) => [i] -> [a] -> [Maybe a]+cherry_pick ids xs = ids.map(\i -> xs.at i) reduce, reduce' :: (a -> a -> a) -> [a] -> a reduce = L.foldl1@@ -119,22 +122,10 @@ inject = flip foldl inject' = flip foldl' -none_of :: (a -> Bool) -> [a] -> Bool-none_of f = any f > not- select, reject :: (a -> Bool) -> [a] -> [a] select = filter reject f = filter (f > not) -inner_map :: (a -> b) -> [[a]] -> [[b]]-inner_map f = map (map f)--inner_reduce :: (a -> a -> a) -> [[a]] -> [a]-inner_reduce f = map (reduce f)--inner_inject :: (Foldable t) => a -> (a -> b -> a) -> [t b] -> [a]-inner_inject x f = map (inject x f)- label_by :: (a -> c) -> [a] -> [(c, a)] label_by f = map (f &&& id) @@ -150,11 +141,6 @@ l = xs.length size = if l P.< n then 1 else l `div` n -apply, send_to :: a -> (a -> b) -> b-apply x f = f x-send_to = apply-- belongs_to :: (Foldable t, Eq a) => t a -> a -> Bool belongs_to = flip elem @@ -162,7 +148,7 @@ has = flip belongs_to indexed :: (Num t, Enum t) => [b] -> [(t, b)]-indexed = zip([0..])+indexed = zip [0..] ljust, rjust :: (Integral i) => i -> a -> [a] -> [a] rjust n x xs @@ -218,12 +204,20 @@ swap :: (a, b) -> (b, a) swap (x,y) = (y,x) -tuple2 :: (Show a) => [a] -> (a, a)-tuple2 = first &&& last+tuple2 :: [a] -> Maybe (a, a)+tuple2 xs = do+ x <- xs.first+ y <- xs.second+ return (x,y) -tuple3 :: (Show a) => [a] -> (a, a, a)-tuple3 xs = (xs.first, xs.second, xs.third)+tuple3 :: (Show a) => [a] -> Maybe (a, a, a)+tuple3 xs = do+ x <- xs.first+ y <- xs.second+ z <- xs.third+ return (x,y,z) + list2 :: (a, a) -> [a] list2 (x,y) = [x,y] @@ -236,12 +230,6 @@ filter_snd :: (b -> Bool) -> [(a, b)] -> [(a, b)] filter_snd f = filter(snd > f) -only_fst :: [(a, b)] -> [a]-only_fst = map fst--only_snd :: [(a, b)] -> [b]-only_snd = map snd- map_fst :: (a -> b) -> [(a, c)] -> [(b, c)] map_fst f = map(\(a,b) -> (f a, b)) @@ -254,8 +242,8 @@ splat3 :: (a -> b -> c -> d) -> (a, b, c) -> d splat3 f (a,b,c) = f a b c -twin :: a -> (a, a)-twin x = (x,x)+clone :: a -> (a, a)+clone x = (x,x) -- Integer from_i :: (Integral a, Num b) => a -> b@@ -283,14 +271,7 @@ trace' :: (Show a) => a -> a trace' x = trace (x.show) x -- -- New from Lab-at :: (Show a, Integral i, Show i) => i -> [a] -> a-at i xs = if i P.< xs.length- then xs !! i- else error - show xs ++ " at " ++ show i ++ " failed"- void :: (Monad m) => m a -> m () void x = x >>= const () > return @@ -315,8 +296,8 @@ replicate :: Integral i => i -> a -> [a] replicate = L.genericReplicate -(!!) :: Integral a => [b] -> a -> b-(!!) = index+(!!) :: Integral a => [b] -> a -> Maybe b+(!!) = flip at to_f :: (Real a, Fractional b) => a -> b to_f = realToFrac @@ -324,15 +305,9 @@ sleep :: (RealFrac a) => a -> IO () sleep x = threadDelay - round - (x * 1000000) -first_or :: a -> [a] -> a-first_or x xs = case xs of- [] -> x- (y:_) -> y- puts :: String -> IO () puts = putStrLn - exit_success :: IO () exit_success = exitWith ExitSuccess @@ -342,9 +317,6 @@ insert_unique :: (Eq a) => a -> [a] -> [a] insert_unique x xs = x : xs.reject (is x) -squeeze :: (Monad m) => m (m a) -> m a-squeeze = Monad.join- end :: (Monad m) => m () end = return () @@ -356,3 +328,12 @@ s2l :: StrictByteString.ByteString -> LazyByteString.ByteString s2l x = LazyByteString.fromChunks [x]++ap2 f x1 z = f <$> x1 <*> z +ap3 f x1 x2 z = ap2 f x1 x2 <*> z+ap4 f x1 x2 x3 z = ap3 f x1 x2 x3 <*> z+ap5 f x1 x2 x3 x4 z = ap4 f x1 x2 x3 x4 <*> z+ap6 f x1 x2 x3 x4 x5 z = ap5 f x1 x2 x3 x4 x5 <*> z+ap7 f x1 x2 x3 x4 x5 x6 z = ap6 f x1 x2 x3 x4 x5 x6 <*> z+ap8 f x1 x2 x3 x4 x5 x6 x7 z = ap7 f x1 x2 x3 x4 x5 x6 x7 <*> z+ap9 f x1 x2 x3 x4 x5 x6 x7 x8 z = ap8 f x1 x2 x3 x4 x5 x6 x7 x8 <*> z
src/Air/SimpleMath.hs view
@@ -15,13 +15,6 @@ ] where l = xs.length --encode :: (Eq a) => [a] -> [(Int, a)]-encode xs = xs.L.group.map (length &&& head)--decode :: [(Int, a)] -> [a]-decode xs = xs.map(\(l,x) -> l.times x).join'- hist :: (Num e, A.Ix i) => (i, i) -> [i] -> A.Array i e hist bnds ns = A.accumArray (+) 0 bnds [(n, 1) | n <- ns, A.inRange bnds n]