Skip to content

Commit ca5d02f

Browse files
committed
fix bug in List.map reverseUnrolledMap
was ignoring some list elements
1 parent cadf481 commit ca5d02f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Data/List/Types.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ listMap f = startUnrolledMap unrollLimit where
108108
reverseUnrolledMap chunksAcc $ startUnrolledMap 0 finalChunk
109109

110110
reverseUnrolledMap :: List (List a) -> List b -> List b
111-
reverseUnrolledMap ((x1 : x2 : x3 : _) : cs) acc =
112-
reverseUnrolledMap cs (f x1 : f x2 : f x3 : acc)
111+
reverseUnrolledMap ((x1 : x2 : x3 : x4 : x5 : _) : cs) acc =
112+
reverseUnrolledMap cs (f x1 : f x2 : f x3 : f x4 : f x5 : acc)
113113
-- if we pattern match on Nil, we need a Partial constraint,
114114
-- which kills TCO
115115
reverseUnrolledMap _ acc = acc

test/Test/Data/List.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ testList = do
363363
log "map should be stack-safe"
364364
void $ pure $ map id (1..100000)
365365

366+
log "map should be correct"
367+
assert $ (1..1000000) == map (_ + 1) (0..999999)
368+
366369
log "transpose"
367370
assert $ transpose (l [l [1,2,3], l[4,5,6], l [7,8,9]]) ==
368371
(l [l [1,4,7], l[2,5,8], l [3,6,9]])

0 commit comments

Comments
 (0)