Skip to content
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

make unsnoc handle infinite lists #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mauke
Copy link

@mauke mauke commented Jun 9, 2023

Before:

ghci> take 10 . fst <$> unsnoc [1..]
Just *** Exception: stack overflow

After:

ghci> take 10 . fst <$> unsnoc [1..]
Just [1,2,3,4,5,6,7,8,9,10]

Before:

    ghci> take 10 . fst <$> unsnoc [1..]
    Just *** Exception: stack overflow

After:

    ghci> take 10 . fst <$> unsnoc [1..]
    Just [1,2,3,4,5,6,7,8,9,10]
@mauke
Copy link
Author

mauke commented Jun 9, 2023

... see also haskell/core-libraries-committee#165:

It's important to use a lazy pattern match ~(a, b) in the definition of unsnoc above. Otherwise the function becomes non-productive on infinite lists and (probably more importantly) is prone to stack overflow.

... which is exactly the issue I stumbled over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant