packages feed

list-extras 0.4.0.1 → 0.4.1.1

raw patch · 8 files changed

+137/−71 lines, 8 files

Files

Data/List/Extras.hs view
@@ -1,15 +1,13 @@- {-# OPTIONS_GHC -Wall -fwarn-tabs #-}- ---------------------------------------------------------------- --                                                  ~ 2010.04.05 -- | -- Module      :  Data.List.Extras--- Copyright   :  Copyright (c) 2007--2010 wren ng thornton+-- Copyright   :  Copyright (c) 2007--2012 wren ng thornton -- License     :  BSD3 -- Maintainer  :  wren@community.haskell.org -- Stability   :  stable--- Portability :  portable+-- Portability :  Haskell98 -- -- This module provides a single header for all @Data.List.Extras.*@ -- modules and provides a small number of other utility functions.@@ -33,7 +31,7 @@ -- the function is called with the head and tail of the list. list :: (a -> [a] -> b) -> b -> [a] -> b list _ z []     = z-list f _ (x:xs) = f x xs +list f _ (x:xs) = f x xs  ---------------------------------------------------------------- ----------------------------------------------------------- fin.
Data/List/Extras/Argmax.hs view
@@ -1,15 +1,13 @@- {-# OPTIONS_GHC -Wall -fwarn-tabs #-}- -------------------------------------------------------------------                                                  ~ 2008.08.17+--                                                  ~ 2010.10.15 -- | -- Module      :  Data.List.Extras.ArgMax--- Copyright   :  Copyright (c) 2007--2009 wren ng thornton+-- Copyright   :  Copyright (c) 2007--2012 wren ng thornton -- License     :  BSD3 -- Maintainer  :  wren@community.haskell.org -- Stability   :  experimental--- Portability :  portable+-- Portability :  Haskell98 -- -- This module provides variants of the 'maximum' and 'minimum' -- functions which return the elements for which some function is@@ -43,28 +41,39 @@ -- | Apply a list function safely, i.e. when the list is non-empty. -- All other functions will throw errors on empty lists, so use -- this to make your own safe variations.-catchNull           :: ([a] -> b) -> ([a] -> Maybe b)-catchNull _ []       = Nothing-catchNull f xs@(_:_) = Just (f xs)+catchNull :: ([a] -> b) -> ([a] -> Maybe b)+{-# INLINE catchNull #-}+-- We use the explicit lambda in order to improve inlining in ghc-7.+catchNull f = \xs ->+    case xs of+    []  -> Nothing+    _:_ -> Just (f xs)   -- | Minimize the number of string literals-emptyListError    :: String -> a-emptyListError fun = error $ "Data.List.Extras.Argmax."++fun++": empty list"+emptyListError :: String -> a+{-# NOINLINE emptyListError #-}+emptyListError fun =+    error $ "Data.List.Extras.Argmax."++fun++": empty list"   -- | Apply a list function unsafely. For internal use.-{-# INLINE throwNull #-} throwNull :: String -> (a -> [a] -> b) -> ([a] -> b)-throwNull fun _ []     = emptyListError fun-throwNull _   f (x:xs) = f x xs+{-# INLINE throwNull #-}+-- We use the explicit lambda in order to improve inlining in ghc-7.+throwNull fun f = \xs ->+    case xs of+    []    -> emptyListError fun+    x:xs' -> f x xs'  ---------------------------------------------------------------- ---------------------------------------------------------------- -- | Tail-recursive driver-_argmaxWithMaxBy :: (b -> b -> Bool) -> (a -> b)-                 -> a -> [a] -> (a,b)-_argmaxWithMaxBy isBetterThan f x xs = foldl' cmp (x, f x) xs+_argmaxWithMaxBy :: (b -> b -> Bool) -> (a -> b) -> a -> [a] -> (a,b)+{-# INLINE _argmaxWithMaxBy #-}+-- We use the explicit lambda in order to improve inlining in ghc-7.+_argmaxWithMaxBy isBetterThan f =+    \x xs -> foldl' cmp (x, f x) xs     where     cmp bfb@(_,fb) a =         let  fa = f a in@@ -73,10 +82,12 @@         else bfb  --- | Tail-recursive driver for all-variants-_argmaxesWithMaxBy :: (b -> b -> Ordering) -> (a -> b)-                   -> a -> [a] -> ([a],b)-_argmaxesWithMaxBy isBetterEqualThan f x xs = foldl' cmp ([x], f x) xs+-- | Tail-recursive driver+_argmaxesWithMaxBy :: (b -> b -> Ordering) -> (a -> b) -> a -> [a] -> ([a],b)+{-# INLINE _argmaxesWithMaxBy #-}+-- We use the explicit lambda in order to improve inlining in ghc-7.+_argmaxesWithMaxBy isBetterEqualThan f =+    \x xs -> foldl' cmp ([x], f x) xs     where     cmp bsfb@(bs,fb) a =         let  fa = f a in@@ -85,14 +96,17 @@              EQ -> (a:bs, fb)              _  -> bsfb -_argmaxBy         :: (b -> b -> Bool) -> (a -> b)-                  -> a -> [a] -> a-_argmaxBy k f x xs = fst (_argmaxWithMaxBy k f x xs) +_argmaxBy :: (b -> b -> Bool) -> (a -> b) -> a -> [a] -> a+{-# INLINE _argmaxBy #-}+-- We use the point-free style in order to improve inlining in ghc-7.+_argmaxBy k f = (fst .) . _argmaxWithMaxBy k f -_argmaxesBy         :: (b -> b -> Ordering) -> (a -> b)-                    -> a -> [a] -> [a]-_argmaxesBy k f x xs = fst (_argmaxesWithMaxBy k f x xs)++_argmaxesBy :: (b -> b -> Ordering) -> (a -> b) -> a -> [a] -> [a]+{-# INLINE _argmaxesBy #-}+-- We use the point-free style in order to improve inlining in ghc-7.+_argmaxesBy k f = (fst .) . _argmaxesWithMaxBy k f  ---------------------------------------------------------------- ----------------------------------------------------------------
Data/List/Extras/LazyLength.hs view
@@ -6,18 +6,24 @@ -- may disconcert users. {-# OPTIONS_GHC -Wall -fwarn-tabs #-} --- We would need this in order to ensure the rules are parsed.--- OPTIONS_GHC -O2 -fglasgow-exts+-- Unfortunately GHC < 6.10 needs -fglasgow-exts in order to actually+-- parse RULES (see -ddump-rules); the -frewrite-rules flag only+-- enables the application of rules, instead of doing what we want.+-- Apparently this is fixed in 6.10.+--+-- http://hackage.haskell.org/trac/ghc/ticket/2213+-- http://www.mail-archive.com/glasgow-haskell-users@haskell.org/msg14313.html+-- OPTIONS_GHC -O2 -fglasgow-exts -frewrite-rules  ---------------------------------------------------------------- --                                                  ~ 2009.04.02 -- | -- Module      :  Data.List.Extras.LazyLength--- Copyright   :  Copyright (c) 2007--2009 wren ng thornton+-- Copyright   :  Copyright (c) 2007--2012 wren ng thornton -- License     :  BSD3 -- Maintainer  :  wren@community.haskell.org -- Stability   :  stable--- Portability :  portable+-- Portability :  Haskell98 -- -- This module provides least-strict functions for getting a list's -- length and doing natural things with it.@@ -62,7 +68,7 @@ -- boundary length and so the function should not rely on the true -- values of either of the numbers being compared. -lengthBound      :: Int -> (Int -> Int -> a) -> [b] -> a+lengthBound :: Int -> (Int -> Int -> a) -> [b] -> a lengthBound n cmp xs     | n < 0       = case xs of                     []    -> cmp n 0@@ -74,6 +80,8 @@     go n' (_:xs') = (go $! n'-1) xs'  {- bad RULES+-- The rules themselves are correct but they alter program semantics+-- regarding bottoms, depending on whether they fire or not.  "lengthBound/(>)"      forall n xs. n >  length xs = lengthBound n (>)  xs "lengthBound/(>=)"     forall n xs. n >= length xs = lengthBound n (>=) xs@@ -113,6 +121,8 @@   {- bad RULES+-- The rules themselves are correct but they alter program semantics+-- regarding bottoms, depending on whether they fire or not.  "lengthCompare/(>)"  forall xs ys.                             length xs >  length ys = lengthCompare xs ys == GT
Data/List/Extras/Pair.hs view
@@ -1,15 +1,13 @@- {-# OPTIONS_GHC -Wall -fwarn-tabs #-}- -------------------------------------------------------------------                                                  ~ 2010.05.31+--                                                  ~ 2010.11.15 -- | -- Module      :  Data.List.Extras.Pair--- Copyright   :  Copyright (c) 2007--2009 wren ng thornton+-- Copyright   :  Copyright (c) 2007--2012 wren ng thornton -- License     :  BSD3 -- Maintainer  :  wren@community.haskell.org -- Stability   :  stable--- Portability :  portable+-- Portability :  Haskell98 -- -- This module provides safe zipping functions which will fail -- (return 'Nothing') on uneven length lists.@@ -32,7 +30,7 @@ ---------------------------------------------------------------- -- TODO: benchmark fusion performance of: -----     foldr cons nil ... zipWith (,)+--     foldr cons nil .: zipWith (,) --     zipWithBy (,) cons nil -- -- ...That is, the latter is a manual fusion of the former, but@@ -43,8 +41,9 @@ zipWithBy :: (a -> b -> c)       -- tuple homomorphism           -> (c -> d -> d) -> d  -- list  homomorphism           -> [a] -> [b] -> d     -- a @zip@ function--zipWithBy k f z xs' ys' = zipWB xs' ys' id+{-# INLINE zipWithBy #-}+-- We use the explicit lambda in order to improve inlining in ghc-7.+zipWithBy k f z = \xs ys -> zipWB xs ys id     where     zipWB (x:xs) (y:ys) cc = zipWB xs ys (cc . f (k x y))     zipWB _      _      cc = cc z@@ -52,7 +51,8 @@  -- | A version of 'zip' that uses a user-defined list homomorphism. zipBy :: ((a,b) -> d -> d) -> d -> [a] -> [b] -> d-zipBy  = zipWithBy (,)+{-# INLINE zipBy #-}+zipBy = zipWithBy (,)   ----------------------------------------------------------------@@ -77,8 +77,9 @@            -> (c -> d -> d)          -- @(:)@ list  homomorphism, pt. 1            -> d                      -- @[]@  list  homomorphism, pt. 2            -> [a] -> [b] -> Maybe d  -- a safer @zip@ function--pairWithBy k f z xs' ys' = pairWB xs' ys' id+{-# INLINE pairWithBy #-}+-- We use the explicit lambda in order to improve inlining in ghc-7.+pairWithBy k f z = \xs ys -> pairWB xs ys id     where     -- N.B. Strict accumulators are usually awesome, but don't     -- even consider it when doing CPS! Making @cc@ strict degrades@@ -96,20 +97,21 @@ ----------------------------------------------------------------  -- | A safe version of 'zipWith'.-pairWith  :: (a -> b -> c)-          -> [a] -> [b] -> Maybe [c]+pairWith :: (a -> b -> c) -> [a] -> [b] -> Maybe [c]+{-# INLINE pairWith #-} pairWith f = pairWithBy f (:) []   -- | A safe version of 'zip' that uses a user-defined list homomorphism.-pairBy :: ((a,b) -> d -> d) -> d-       -> [a] -> [b] -> Maybe d-pairBy  = pairWithBy (,)+pairBy :: ((a,b) -> d -> d) -> d -> [a] -> [b] -> Maybe d+{-# INLINE pairBy #-}+pairBy = pairWithBy (,)   -- | A safe version of 'zip'. pair :: [a] -> [b] -> Maybe [(a,b)]-pair  = pairBy (:) []+{-# INLINE pair #-}+pair = pairWithBy (,) (:) []   ----------------------------------------------------------------@@ -119,14 +121,16 @@ -- | A bijection from a list of functions and a list of arguments -- to a list of results of applying the functions bijectively. biject :: [a -> b] -> [a] -> Maybe [b]-biject  = pairWith ($) -- 'id' also works+{-# INLINE biject #-}+biject = pairWith ($) -- 'id' also works   -- | A version of 'biject' that applies functions strictly. N.B. -- the list is still lazily evaluated, this just makes the functions -- strict in their argument. biject' :: [a -> b] -> [a] -> Maybe [b]-biject'  = pairWith ($!)+{-# INLINE biject' #-}+biject' = pairWith ($!)  ---------------------------------------------------------------- ----------------------------------------------------------- fin.
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2007--2009, wren ng thornton.+Copyright (c) 2007--2012, wren ng thornton. ALL RIGHTS RESERVED.  Redistribution and use in source and binary forms, with or without
Prelude/Listless.hs view
@@ -1,19 +1,21 @@- {-# OPTIONS_GHC -Wall -fwarn-tabs #-}-+{-# LANGUAGE CPP #-} -------------------------------------------------------------------                                                  ~ 2008.07.20+--                                                  ~ 2012.09.26 -- | -- Module      :  Prelude.Listless--- Copyright   :  Copyright (c) 2007--2009 wren ng thornton+-- Copyright   :  Copyright (c) 2007--2012 wren ng thornton -- License     :  BSD3 -- Maintainer  :  wren@community.haskell.org -- Stability   :  stable--- Portability :  portable+-- Portability :  Haskell98 (+CPP) -- -- This module provides the "Prelude" but removing all the list -- functions. This is helpful for modules that overload those--- function names to work for other types.+-- function names to work for other types. Note that on GHC 7.6 and+-- above @catch@ is no longer exported from the Prelude, and also+-- not re-exported from here; whereas, on earlier versions of GHC+-- (and non-GHC compilers) we still re-export it. -- -- Be sure to disable the implicit importing of the prelude when -- you import this one (by passing @-fno-implicit-prelude@ for GHC,@@ -30,7 +32,10 @@     Fractional(..), Functor(..), IO, IOError, Int, Integer,     Integral(..), Maybe(..), Monad(..), Num(..), Ord(..), Ordering(..),     Rational, Read(..), ReadS, Real(..), RealFloat(..), RealFrac(..),-    Show(..), ShowS, String, (^), (^^), appendFile, asTypeOf, catch,+    Show(..), ShowS, String, (^), (^^), appendFile, asTypeOf,+#if __GLASGOW_HASKELL__ < 706+    catch,+#endif     const, curry, either, error, even, flip, fromIntegral, fst,     gcd, getChar, getContents, getLine, id, interact, ioError, lcm,     lex, maybe, not, odd, otherwise, print, putChar, putStr, putStrLn,
+ VERSION view
@@ -0,0 +1,21 @@+0.4.1 (2012-09-26):+    - Prelude.Listless: Guarded re-export of Prelude.catch with CPP+0.4.0.1 (2010-05-31):+    - Fixed some typos in the cabal file regarding base and the Prelude+0.4.0 (2010-05-31):+    - Added Data.List.Extras.list (by Tom Lokhorst)+    - Changed the type of Data.List.Extras.Pair.zipBy to be correct++0.3.0 (2009-04-02):+    - Relaxed type for Data.List.Extras.Pair.pairBy+    - Removed rewrite rules for Data.List.Extras.LazyLength.*++0.2.2.1 (2008-10-12):+    - Now compiles under GHC 6.10+0.2.1 (2008-08-17):+    - Rewrite rules for Data.List.Extras.LazyLength.* actually get picked up+0.2.0 (2008-07-26):+    - Overhauled Data.List.Extras.Argmax++0.1.0 (2008-07-21):+    - Initial public release
list-extras.cabal view
@@ -1,18 +1,22 @@ ------------------------------------------------------------------- wren ng thornton <wren@community.haskell.org>    ~ 2010.05.31+-- wren ng thornton <wren@community.haskell.org>    ~ 2012.09.26 ---------------------------------------------------------------- -Name:           list-extras-Version:        0.4.0.1-Cabal-Version:  >= 1.2+-- By and large Cabal >=1.2 is fine; but >= 1.6 gives tested-with:+-- and source-repository:.+Cabal-Version:  >= 1.6 Build-Type:     Simple++Name:           list-extras+Version:        0.4.1.1 Stability:      stable-Copyright:      Copyright (c) 2007--2010 wren ng thornton-License:        BSD3-License-File:   LICENSE+Homepage:       http://code.haskell.org/~wren/ Author:         wren ng thornton Maintainer:     wren@community.haskell.org-Homepage:       http://code.haskell.org/~wren/+Copyright:      Copyright (c) 2007--2012 wren ng thornton+License:        BSD3+License-File:   LICENSE+ Category:       List Synopsis:       Common not-so-common functions for lists Description:    Common not-so-common functions for lists.@@ -26,13 +30,22 @@                 maintain a separate package I can share the                 @Data.List.Extras.Foo@ namespace. +Extra-source-files:+    VERSION+Source-Repository head+    Type:     darcs+    Location: http://community.haskell.org/~wren/list-extras +---------------------------------------------------------------- Flag base4     Description: base-4.0 deprecated Prelude which is imported qualified     Default:     True +---------------------------------------------------------------- Library     Exposed-Modules: Prelude.Listless+                   -- , Data.List.BoehmBerarducci+                   -- , Data.List.Scott                    , Data.List.Extras                    , Data.List.Extras.Argmax                    , Data.List.Extras.LazyLength@@ -43,6 +56,7 @@     else         -- TODO: What else do we need to do?         Build-Depends: base < 4+    -- Build-Depends: data-or  ---------------------------------------------------------------- ----------------------------------------------------------- fin.