Skip to content

some and many fail to converge #5

Description

@andersk

The default definitions of some and many fail to converge for Stream.

λ> toList (many (return 1 <|> return 2) :: Stream [Int])

It’s possible to come up with definitions of some and many that work better than the default ones:

  some v = (:) <$> suspended v <*> many v
  many v = suspended (some v) <|> pure []
λ> toList (many (return 1 <|> return 2) :: Stream [Int])
[[],[1],[2],[1,1],[2,1],[1,2],[2,2],[1,1,1],[2,1,1],[1,2,1],[2,2,1],[1,1,2],[2,1,2],[1,2,2],[2,2,2],[1,1,1,1],[2,1,1,1],[1,2,1,1],[2,2,1,1],[1,1,2,1],[2,1,2,1],[1,2,2,1],[2,2,2,1],[1,1,1,2],[2,1,1,2],[1,2,1,2],[2,2,1,2],[1,1,2,2],[2,1,2,2],[1,2,2,2],[2,2,2,2],[1,1,1,1,1],

Though perhaps this indicates a deeper problem with the existing definitions of <$>, <*>, and <|>?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions