Skip to content

Make append stack-safe #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Data/List/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ instance ordList :: Ord a => Ord (List a) where
other -> other

instance semigroupList :: Semigroup (List a) where
append Nil ys = ys
append (x : xs) ys = x : (xs <> ys)
append xs ys = foldr (:) ys xs

instance monoidList :: Monoid (List a) where
mempty = Nil
Expand Down
7 changes: 7 additions & 0 deletions test/Test/Data/List.purs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ testList = do
let xs = fromFoldable (range 1 100000)
assert $ traverse Just xs == Just xs

log "append should concatenate two lists"
assert $ (l [1, 2]) <> (l [3, 4]) == (l [1, 2, 3, 4])

log "append should be stack-safe"
void $ pure $ xs <> xs


step :: Int -> Maybe (Tuple Int Int)
step 6 = Nothing
step n = Just (Tuple n (n + 1))
Expand Down