list-extras 0.2.2.1 → 0.3.0
raw patch · 4 files changed
+26/−30 lines, 4 files
Files
- Data/List/Extras/LazyLength.hs +20/−24
- Data/List/Extras/Pair.hs +3/−3
- LICENSE +1/−1
- list-extras.cabal +2/−2
Data/List/Extras/LazyLength.hs view
@@ -3,15 +3,14 @@ -- longer suppresses the warnings for orphaned RULES. Hence -Werror -- will make things crash on those systems, and even if that's -- removed then -Wall will send up too many false positives which--- may disconcert users. So now this file is now running without--- linting. Eheu!-{-# OPTIONS_GHC -fwarn-tabs #-}+-- may disconcert users.+{-# OPTIONS_GHC -Wall -fwarn-tabs #-} --- We need this in order to ensure the rules are picked up-{-# OPTIONS_GHC -O2 -fglasgow-exts #-}+-- We would need this in order to ensure the rules are parsed.+-- OPTIONS_GHC -O2 -fglasgow-exts ------------------------------------------------------------------- ~ 2008.08.23+-- ~ 2009.04.02 -- | -- Module : Data.List.Extras.LazyLength -- Copyright : Copyright (c) 2007--2008 wren ng thornton@@ -21,9 +20,7 @@ -- Portability : portable -- -- This module provides least-strict functions for getting a list's--- length and doing natural things with it. On GHC this module also--- uses rewrite rules to convert certain calls to 'length' into our--- least-strict versions.+-- length and doing natural things with it. -- -- The regular version of @length@ will traverse the entire spine -- of the list in order to return an answer. For comparing the@@ -37,13 +34,15 @@ -- of an answer which retains the proper semantics. An option for -- doing this is to return Peano integers which can be decremented -- as much as necessary and no further (i.e. at most one more than--- the bound). Of course, Peano integers are woefully inefficient--- and would wreck the cache and burn heap. This module provides--- functions with the same lazy effect as if we used Peano integers,--- but does so efficiently instead.+-- the bound). Of course, Peano integers are woefully inefficient.+-- This module provides functions with the same lazy effect but+-- does so efficiently instead. ----- (For Peano integers see numbers:"Data.Number.Natural" or--- non-negative:"Numeric.NonNegative.Class".)+-- As of version 0.3.0 the GHC rules to automatically rewrite+-- certain calls to 'length' into our least-strict versions have+-- been /removed/ for more consistent and predictable semantics.+-- All clients should explicitly call these least-strict functions+-- if they want the least-strict behavior. ---------------------------------------------------------------- module Data.List.Extras.LazyLength@@ -54,9 +53,7 @@ ---------------------------------------------------------------- ---------------------------------------------------------------- -- | A variant of 'length' which is least-strict for comparing--- against a boundary length. This function is defined primarily--- for use by rewrite rules rather than for direct use (though it's--- fine for that too).+-- against a boundary length. -- -- @lengthBound@ is polymorphic in the return of the helper -- function so we can use 'compare' as well as '>', '>=', '==',@@ -76,7 +73,7 @@ go 0 (_:_) = cmp 0 1 go n' (_:xs') = (go $! n'-1) xs' -{-# RULES+{- bad RULES "lengthBound/(>)" forall n xs. n > length xs = lengthBound n (>) xs "lengthBound/(>=)" forall n xs. n >= length xs = lengthBound n (>=) xs@@ -95,7 +92,7 @@ "lengthBound\\(<)" forall n xs. length xs < n = lengthBound n (>) xs "lengthBound\\compare" forall n xs. compare (length xs) n = lengthBound n (flip compare) xs- #-}+ -} ----------------------------------------------------------------@@ -103,8 +100,7 @@ -- | A variant of 'length' which is least-strict for comparing -- the lengths of two lists. This is as strict as the length of the -- shorter list (which allows comparing an infinite list against a--- finite list). The function itself is trivial, but again it's--- designed primarily for rewrite rules.+-- finite list). -- -- If you're going to immediately follow this with a 'zip' function -- then see "Data.List.Extras.Pair" instead.@@ -116,7 +112,7 @@ lengthCompare (_:xs) (_:ys) = lengthCompare xs ys -{-# RULES+{- bad RULES "lengthCompare/(>)" forall xs ys. length xs > length ys = lengthCompare xs ys == GT@@ -133,7 +129,7 @@ "lengthCompare/compare" forall xs ys. compare (length xs) (length ys) = lengthCompare xs ys- #-}+ -} ---------------------------------------------------------------- ----------------------------------------------------------- fin.
Data/List/Extras/Pair.hs view
@@ -2,7 +2,7 @@ {-# OPTIONS_GHC -Wall -fwarn-tabs #-} ------------------------------------------------------------------- ~ 2008.08.12+-- ~ 2009.04.02 -- | -- Module : Data.List.Extras.Pair -- Copyright : Copyright (c) 2007--2008 wren ng thornton@@ -101,8 +101,8 @@ -- | A safe version of 'zip' that uses a user-defined list homomorphism.-pairBy :: ((a,b) -> m (a,b) -> m (a,b)) -> m (a,b)- -> [a] -> [b] -> Maybe (m (a,b))+pairBy :: ((a,b) -> d -> d) -> d+ -> [a] -> [b] -> Maybe d pairBy = pairWithBy (,)
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2007--2008, wren ng thornton.+Copyright (c) 2007--2009, wren ng thornton. ALL RIGHTS RESERVED. Redistribution and use in source and binary forms, with or without
list-extras.cabal view
@@ -1,9 +1,9 @@ ------------------------------------------------------------------- wren ng thornton <wren@community.haskell.org> ~ 2008.10.12+-- wren ng thornton <wren@community.haskell.org> ~ 2009.04.02 ---------------------------------------------------------------- Name: list-extras-Version: 0.2.2.1+Version: 0.3.0 Cabal-Version: >= 1.2 Build-Type: Simple Stability: stable