Skip to content

Commit abc5578

Browse files
authored
Merge pull request #89 from sammthomson/master
Make `append` stack-safe
2 parents cb7c51f + 8e409db commit abc5578

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Data/List/Types.purs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ instance ordList :: Ord a => Ord (List a) where
5050
other -> other
5151

5252
instance semigroupList :: Semigroup (List a) where
53-
append Nil ys = ys
54-
append (x : xs) ys = x : (xs <> ys)
53+
append xs ys = foldr (:) ys xs
5554

5655
instance monoidList :: Monoid (List a) where
5756
mempty = Nil

test/Test/Data/List.purs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,13 @@ testList = do
319319
let xs = fromFoldable (range 1 100000)
320320
assert $ traverse Just xs == Just xs
321321

322+
log "append should concatenate two lists"
323+
assert $ (l [1, 2]) <> (l [3, 4]) == (l [1, 2, 3, 4])
324+
325+
log "append should be stack-safe"
326+
void $ pure $ xs <> xs
327+
328+
322329
step :: Int -> Maybe (Tuple Int Int)
323330
step 6 = Nothing
324331
step n = Just (Tuple n (n + 1))

0 commit comments

Comments
 (0)