@@ -1382,7 +1382,7 @@ fromFunction len f | len < 0 = error "Data.Sequence.fromFunction called with neg
1382
1382
3 -> Deep (3 * s) (Two (b i) (b (i+ s))) Empty (One (b (i+ 2 * s)))
1383
1383
4 -> Deep (4 * s) (Two (b i) (b (i+ s))) Empty (Two (b (i+ 2 * s)) (b (i+ 3 * s)))
1384
1384
5 -> Deep (5 * s) (Three (b i) (b (i+ s)) (b (i+ 2 * s))) Empty (Two (b (i+ 3 * s)) (b (i+ 4 * s)))
1385
- 6 -> Deep (5 * s) (Three (b i) (b (i+ s)) (b (i+ 2 * s))) Empty (Three (b (i+ 3 * s)) (b (i+ 4 * s)) (b (i+ 5 * s)))
1385
+ 6 -> Deep (6 * s) (Three (b i) (b (i+ s)) (b (i+ 2 * s))) Empty (Three (b (i+ 3 * s)) (b (i+ 4 * s)) (b (i+ 5 * s)))
1386
1386
_ -> case trees `quotRem` 3 of
1387
1387
(trees',1 ) -> Deep (trees* s) (Two (b i) (b (i+ s)))
1388
1388
(create (\ j -> Node3 (3 * s) (b j) (b (j+ s)) (b (j+ 2 * s))) (3 * s) (i+ 2 * s) (trees'- 1 ))
@@ -1937,12 +1937,16 @@ zip = zipWith (,)
1937
1937
-- For example, @zipWith (+)@ is applied to two sequences to take the
1938
1938
-- sequence of corresponding sums.
1939
1939
zipWith :: (a -> b -> c ) -> Seq a -> Seq b -> Seq c
1940
- zipWith f s1 s2 = splitMap splitAt' ( \ s a -> f a (getSingleton s)) s2' s1 '
1940
+ zipWith f s1 s2 = zipWith' f s1' s2 '
1941
1941
where
1942
1942
minLen = min (length s1) (length s2)
1943
1943
s1' = take minLen s1
1944
1944
s2' = take minLen s2
1945
1945
1946
+ -- | A version of zipWith that assumes the sequences have the same length.
1947
+ zipWith' :: (a -> b -> c ) -> Seq a -> Seq b -> Seq c
1948
+ zipWith' f s1 s2 = splitMap splitAt' (\ s a -> f a (getSingleton s)) s2 s1
1949
+
1946
1950
-- | /O(min(n1,n2,n3))/. 'zip3' takes three sequences and returns a
1947
1951
-- sequence of triples, analogous to 'zip'.
1948
1952
zip3 :: Seq a -> Seq b -> Seq c -> Seq (a ,b ,c )
@@ -1952,14 +1956,16 @@ zip3 = zipWith3 (,,)
1952
1956
-- three elements, as well as three sequences and returns a sequence of
1953
1957
-- their point-wise combinations, analogous to 'zipWith'.
1954
1958
zipWith3 :: (a -> b -> c -> d ) -> Seq a -> Seq b -> Seq c -> Seq d
1955
- zipWith3 f s1 s2 s3 = splitMap (\ i (s,t) -> case (splitAt' i s, splitAt' i t) of ((s', s''), (t', t'')) -> ((s',t'),(s'',t'')))
1956
- (\ (b,c) a -> f a (getSingleton b) (getSingleton c)) (s2',s3') s1'
1959
+ zipWith3 f s1 s2 s3 = zipWith' ($) (zipWith' f s1' s2') s3'
1957
1960
where
1958
1961
minLen = minimum [length s1, length s2, length s3]
1959
1962
s1' = take minLen s1
1960
1963
s2' = take minLen s2
1961
1964
s3' = take minLen s3
1962
1965
1966
+ zipWith3' :: (a -> b -> c -> d ) -> Seq a -> Seq b -> Seq c -> Seq d
1967
+ zipWith3' f s1 s2 s3 = zipWith' ($) (zipWith' f s1 s2) s3
1968
+
1963
1969
-- | /O(min(n1,n2,n3,n4))/. 'zip4' takes four sequences and returns a
1964
1970
-- sequence of quadruples, analogous to 'zip'.
1965
1971
zip4 :: Seq a -> Seq b -> Seq c -> Seq d -> Seq (a ,b ,c ,d )
@@ -1969,8 +1975,7 @@ zip4 = zipWith4 (,,,)
1969
1975
-- four elements, as well as four sequences and returns a sequence of
1970
1976
-- their point-wise combinations, analogous to 'zipWith'.
1971
1977
zipWith4 :: (a -> b -> c -> d -> e ) -> Seq a -> Seq b -> Seq c -> Seq d -> Seq e
1972
- zipWith4 f s1 s2 s3 s4 = splitMap (\ i (s,t,u) -> case (splitAt' i s, splitAt' i t, splitAt' i u) of ((s',s''),(t',t''),(u',u'')) -> ((s',t',u'),(s'',t'',u'')))
1973
- (\ (b, c, d) a -> f a (getSingleton b) (getSingleton c) (getSingleton d)) (s2',s3',s4') s1'
1978
+ zipWith4 f s1 s2 s3 s4 = zipWith' ($) (zipWith3' f s1' s2' s3') s4'
1974
1979
where
1975
1980
minLen = minimum [length s1, length s2, length s3, length s4]
1976
1981
s1' = take minLen s1
0 commit comments