Make Control.Exception buildable by nhc98.
[haskell-directory.git] / GHC / PArr.hs
index 853fc00..cd2f03b 100644 (file)
@@ -137,9 +137,12 @@ module GHC.PArr (
   bpermuteP,           -- :: [:Int:] -> [:e:] ->          [:e:]
   dpermuteP,           -- :: [:Int:] -> [:e:] -> [:e:] -> [:e:]
   crossP,              -- :: [:a:] -> [:b:] -> [:(a, b):]
+  crossMapP,           -- :: [:a:] -> (a -> [:b:]) -> [:(a, b):]
   indexOfP             -- :: (a -> Bool) -> [:a:] -> [:Int:]
 ) where
 
+#ifndef __HADDOCK__
+
 import Prelude
 
 import GHC.ST   ( ST(..), STRep, runST )
@@ -532,6 +535,25 @@ crossP a1 a2  = let
                zipP x1 x2
  -}
 
+-- |Compute a cross of an array and the arrays produced by the given function
+-- for the elements of the first array.
+--
+crossMapP :: [:a:] -> (a -> [:b:]) -> [:(a, b):]
+crossMapP a f = let
+                 bs   = mapP f a
+                 segd = mapP lengthP bs
+                 as   = zipWithP replicateP segd a
+               in
+               zipP (concatP as) (concatP bs)
+
+{- The following may seem more straight forward, but the above is very cheap
+   with segmented arrays, as `mapP lengthP', `zipP', and `concatP' are
+   constant time, and `map f' uses the lifted version of `f'.
+
+crossMapP a f = concatP $ mapP (\x -> mapP ((,) x) (f x)) a
+
+ -}
+
 -- computes an index array for all elements of the second argument for which
 -- the predicate yields `True' (EXPORTED)
 --
@@ -692,3 +714,6 @@ writeMPArr (MPArr n# marr#) (I# i#) e
   | otherwise = error $ "writeMPArr: out of bounds parallel array index; " ++
                        "idx = " ++ show (I# i#) ++ ", arr len = "
                        ++ show (I# n#)
+
+#endif /* __HADDOCK__ */
+