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

Traversal over streams is unergonomic #48

Closed
samhh opened this issue Jan 25, 2022 · 4 comments · Fixed by #171
Closed

Traversal over streams is unergonomic #48

samhh opened this issue Jan 25, 2022 · 4 comments · Fixed by #171

Comments

@samhh
Copy link
Member

samhh commented Jan 25, 2022

Context: #39

Worth exploring ways to simplify and condense it.

@samhh
Copy link
Member Author

samhh commented Jan 27, 2022

Really we want a way to generically traverse over Stream in our recursive datatypes. Unfortunately, because our datatypes are mutually recursive, I think the recursion schemes approach becomes substantially more complex. Not that I've necessarily fully wrapped my head around ordinary recursion schemes. 🙈

Lenses are something else to look at. If we go this route we should probably prefer optics over lens.

@samhh samhh mentioned this issue Feb 1, 2022
@samhh samhh mentioned this issue May 31, 2022
2 tasks
@samhh
Copy link
Member Author

samhh commented Jun 1, 2022

This came up again in linting for getStream. It's traversal more generally that's a challenge.

@samhh samhh changed the title Mapping over nested sum types is verbose Traversal over streams is unergonomic Jun 27, 2022
@samhh samhh pinned this issue Jun 27, 2022
@samhh
Copy link
Member Author

samhh commented Jun 27, 2022

Came up again in mapTokens which could at least reuse some of the stuff defined for flattening.

@samhh
Copy link
Member Author

samhh commented Jul 29, 2022

For better linting output we need to retain source span information
in the AST (#142). A naive implementation might look like this:

type Stream = [(Token, SourceSpan)]

This makes for a relatively small lib/ diff, and all else looks rosy until we contemplate how we write tests. Where now we might write Plaintext "foo", we'd now need to provide source information. And we'd have to do this everywhere in our tests, and it'd be nonsense that we never use anyway.

A similar problem presents when flattening. It's a lossless procedure in which any source information should be thrown away as it's really no longer valid.

This makes the idea of making our AST parameterised, recursion schemes or not, very tempting. In that scenario our tests can continue to target [Token], but our parser output and linting input could be [(Token, SourceSpan)]. Flattening would transform the latter to the former.

Edit: This describes what I want to do: https://www.reddit.com/r/haskell/comments/sxsj4m/what_are_strategies_for_tracking_type_checking/hxu2tsj/

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