From f42d88adb84299941a6be23fa73a9bb6ceeba475 Mon Sep 17 00:00:00 2001 From: Manuel M T Chakravarty Date: Mon, 2 Apr 2007 08:29:06 +0000 Subject: [PATCH] Function crossMapP for fixing desugaring of comprehensions Merge into 6.6 branch. --- GHC/PArr.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/GHC/PArr.hs b/GHC/PArr.hs index 853fc00..0b5154e 100644 --- a/GHC/PArr.hs +++ b/GHC/PArr.hs @@ -137,6 +137,7 @@ 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 @@ -532,6 +533,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) -- -- 1.7.10.4