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

Snoclists? #2684

Open
gallais opened this issue Mar 21, 2025 · 7 comments
Open

Snoclists? #2684

gallais opened this issue Mar 21, 2025 · 7 comments

Comments

@gallais
Copy link
Member

gallais commented Mar 21, 2025

Snoclists (lists that grow on the right rather than the left) are commonly used when
representing syntaxes with binding because they grow the same way contexts grow
which allows you to transcribe everything without having to "think backwards".

They're also really useful to represent the intermediate state of a computation slowly
going through a list left-to-right with the "fish" combinator having elements in the
middle freely flow from one side of the divide to the other without the need to deploy
rewrite rules (which you would need if you were using a pair of lists instead).

Are we open to adding them to the stdlib (I'm finally open this up because I need them
for the nth time and they're not available)? They're part of Idris 2's prelude for instance.

@JacquesCarette
Copy link
Contributor

Strong YES from me.

Not only is your reasoning sound, one can also witness that Agda is used a lot by people doing PL meta-theory. We should strive to make their lives easier.

@Taneb
Copy link
Member

Taneb commented Mar 21, 2025

Can this be implemented as pattern synonyms on List, so we don't need to reimplement all the functionality?

@jamesmckinna
Copy link
Contributor

jamesmckinna commented Mar 22, 2025

Yes from me as well.

To @Taneb , at least from my memory of trying this the last time I refactored the Data.List.Base.InitLast section, no it can't be done with pattern synonyms, without (re)evaluating the whole list in your hand, as it were.

To @gallais given the intimate intertwining of the two datatypes, does it make sense to have them both defined, in Data.List.Base, or can the dependencies be unwound so as to make a clean separation into two modules, with 'snoc' importing 'cons'?

And: naming... will we be able to agree on names for all the gadgets? Eg. reusing _∷ʳ′_ (ugh! the choice of this name for the constructor, and _∷ʳ_ for the 'snoc' operation on List... is perhaps unfortunate)

Ob: names. We have Data.List.Base.InitLast, but Data.List.NonEmpty.Base.SnocView!?

@gallais
Copy link
Member Author

gallais commented Mar 24, 2025

Pattern synonyms don't lead to cleaner goals which is the point of this.

@JacquesCarette
Copy link
Contributor

Sigh - another case where metaprogramming would probably be a reasonable solution.

I've been having many discussions (with @TOTBWF ) about how I think we ought to be able to inform our ITPs about even more of our intentional information (yes, with a 't' here, but I'll live with being able to be more intensional if that's all I can get).

@TOTBWF
Copy link
Contributor

TOTBWF commented Mar 25, 2025

STRONG +1 on this: we've been using https://opam.ocaml.org/packages/bwd/ in RedPRL projects for years and it makes life so much easier.

@gallais
Copy link
Member Author

gallais commented Mar 25, 2025

I just had my last lecture for this (academic) year earlier today so should have a bit
of time reasonably soon-ish to take this on :)

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

No branches or pull requests

5 participants