Skip to content

scanl does not terminate with infinite list #154

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

Closed
sloosch opened this issue Dec 1, 2018 · 0 comments · Fixed by #161
Closed

scanl does not terminate with infinite list #154

sloosch opened this issue Dec 1, 2018 · 0 comments · Fixed by #161

Comments

@sloosch
Copy link

sloosch commented Dec 1, 2018

Hi,

the default scanl is implemented with the Traversable instance of the Lazy List and does not terminate when having an infinite list.

import Data.List.Lazy as List

-- Will not terminate even though "Lazy" may indicates the opposite
foo :: Maybe Int
foo = List.head $ scanl (+) 0 $ List.cycle $ List.fromFoldable [1, 2, 3]

Should the Lazy List have a specialized scanl ?
E.g.

scanl :: forall a b. (b -> a -> b) -> b -> List a -> List b
scanl f init list = List $ defer \_ -> case List.step list of
  List.Nil -> List.Nil
  List.Cons head tail -> 
    let val = f init head in 
    List.Cons val (scanl f val tail)
@kl0tl kl0tl linked a pull request Dec 17, 2020 that will close this issue
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 a pull request may close this issue.

1 participant