Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upList.take throws "Maximum call stack size exceeded" with large numbers #601
Comments
referenced
this issue
in tgecho/xelm
May 13, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
jvoigtlaender
May 28, 2016
Contributor
This version would not have that stack explosion issue:
take : Int -> List a -> List a
take n list =
List.reverse (takeHelper n list [])
takeHelper : Int -> List a -> List a -> List a
takeHelper n list acc =
if n <= 0 then
acc
else
case list of
[] ->
acc
x :: xs ->
takeHelper (n - 1) xs (x :: acc)|
This version would not have that stack explosion issue: take : Int -> List a -> List a
take n list =
List.reverse (takeHelper n list [])
takeHelper : Int -> List a -> List a -> List a
takeHelper n list acc =
if n <= 0 then
acc
else
case list of
[] ->
acc
x :: xs ->
takeHelper (n - 1) xs (x :: acc) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
|
Covered by https://github.com/elm-lang/core/pull/668. |
jvoigtlaender
closed this
Jul 18, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tgecho commentedMay 13, 2016
This happens if you try to take with an
ngreater than about 5707 and the list you're taking from has at least that many items. This did not happen in v0.16.In elm-repl: