1 2 3 4 5 6 7 8 9 10 11 12 13 | toPoints :: ((Int,Int),(Int,Int)) -> UArray Int Double -> UArray (Int,Int) Double -> [[(Double,Double)]]
toPoints ((b0,s0),(b1,s1)) times coords =
[ fwd ++ rwd
| b <- [b1, b1 - 1 .. b0 + 1]
, let fwd = [ (times ! s, coords ! (b - 1, s)) | s <- [s0 .. s1] ]
, let rwd = [ (times ! s, coords ! (b, s)) | s <- [s1, s1 - 1 .. s0] ]
]
{-
This consumes too much memory, because (s1 - s0) is large.
I want the lists that s is drawn from NOT to be shared.
How to force them to be recomputed for each b?
-}
|
1 2 3 4 5 6 7 8 9 10 11 12 | toPoints :: ((Int,Int),(Int,Int)) -> UArray Int Double -> UArray (Int,Int) Double -> [[(Double,Double)]]
toPoints ((b0,s0),(b1,s1)) times coords =
[ fwd ++ rwd
| b <- [b1, b1 - 1 .. b0 + 1]
, let fwd = [ (times ! s, coords ! (b - 1, s)) | s <- up b ]
, let rwd = [ (times ! s, coords ! (b, s)) | s <- down b ]
]
where
up b = [s0 + b - b .. s1]
down b = [s1 + b - b, s1 - 1 .. s0]
{- space leak fixed! but ewww at the ugly -}
|