transitiveClosure,
-- accumulating
- mapAccumL, mapAccumR, mapAccumB,
foldl2, count, all2,
takeList, dropList, splitAtList, split,
removeSpaces,
-- strictness
- foldl', seqList,
+ seqList,
-- pairs
unzipWith,
#include "HsVersions.h"
-import Panic ( panic, trace )
import FastTypes
+#ifdef DEBUG
+import Panic ( panic, trace )
+#endif
+
import Control.Exception ( Exception(..), finally, catchDyn, throw )
import qualified Control.Exception as Exception
import Data.Dynamic ( Typeable )
import System.IO.Unsafe ( unsafePerformIO )
import Data.IORef ( readIORef, writeIORef )
-import qualified Data.List as List ( elem, notElem )
-
+import qualified Data.List as List ( elem )
#ifndef DEBUG
import Data.List ( zipWith4 )
+#else
+import qualified Data.List as List ( notElem )
#endif
import Control.Monad ( when )
%* *
%************************************************************************
-@mapAccumL@ behaves like a combination
-of @map@ and @foldl@;
-it applies a function to each element of a list, passing an accumulating
-parameter from left to right, and returning a final value of this
-accumulator together with the new list.
-
-\begin{code}
-mapAccumL :: (acc -> x -> (acc, y)) -- Function of elt of input list
- -- and accumulator, returning new
- -- accumulator and elt of result list
- -> acc -- Initial accumulator
- -> [x] -- Input list
- -> (acc, [y]) -- Final accumulator and result list
-
-mapAccumL f b [] = (b, [])
-mapAccumL f b (x:xs) = (b'', x':xs') where
- (b', x') = f b x
- (b'', xs') = mapAccumL f b' xs
-\end{code}
-
-@mapAccumR@ does the same, but working from right to left instead. Its type is
-the same as @mapAccumL@, though.
-
-\begin{code}
-mapAccumR :: (acc -> x -> (acc, y)) -- Function of elt of input list
- -- and accumulator, returning new
- -- accumulator and elt of result list
- -> acc -- Initial accumulator
- -> [x] -- Input list
- -> (acc, [y]) -- Final accumulator and result list
-
-mapAccumR f b [] = (b, [])
-mapAccumR f b (x:xs) = (b'', x':xs') where
- (b'', x') = f b' x
- (b', xs') = mapAccumR f b xs
-\end{code}
-
-Here is the bi-directional version, that works from both left and right.
-
-\begin{code}
-mapAccumB :: (accl -> accr -> x -> (accl, accr,y))
- -- Function of elt of input list
- -- and accumulator, returning new
- -- accumulator and elt of result list
- -> accl -- Initial accumulator from left
- -> accr -- Initial accumulator from right
- -> [x] -- Input list
- -> (accl, accr, [y]) -- Final accumulators and result list
-
-mapAccumB f a b [] = (a,b,[])
-mapAccumB f a b (x:xs) = (a'',b'',y:ys)
- where
- (a',b'',y) = f a b' x
- (a'',b',ys) = mapAccumB f a' b xs
-\end{code}
-
-A strict version of foldl.
-
-\begin{code}
-foldl' :: (a -> b -> a) -> a -> [b] -> a
-foldl' f z xs = lgo z xs
- where
- lgo z [] = z
- lgo z (x:xs) = (lgo $! (f z x)) xs
-\end{code}
-
A combination of foldl with zip. It works with equal length lists.
\begin{code}