Skip to content

refactor: avoid Bwd in within and brackets(Worker)#72

Closed
acl-cqc wants to merge 5 commits intorefactor/parser-wcfrom
acl/brackets-avoid-bwd
Closed

refactor: avoid Bwd in within and brackets(Worker)#72
acl-cqc wants to merge 5 commits intorefactor/parser-wcfrom
acl/brackets-avoid-bwd

Conversation

@acl-cqc
Copy link
Collaborator

@acl-cqc acl-cqc commented Dec 20, 2024

I had a bit of a go at #68 ;)...

The Bwd is just building up a return value; if we just use the stack instead (i.e. <$>) then we avoid having to reverse the list. This simplifies within a bit (no need to pass acc), and simplifies bracketsWorker substantially (making brackets == bracketsWorker).

Individual commits compile so you can see the steps.

It's a shame not to be able to combine within and brackets because they are very very similar (the | Just b <- opener (_tok t) = do case in particular); I tried using a Maybe (FC, BracketType) for ctx and that almost did it but doesn't copy with within needing extra return values :-(. (One could have a Maybe return value, and "contract" that Just-in-means-Just-out, I suppose; but really you'd need a type class which is gonna be tooooo much boilerplate)

@acl-cqc
Copy link
Collaborator Author

acl-cqc commented Dec 20, 2024

Closing in favour of #73

@acl-cqc acl-cqc closed this Dec 20, 2024
croyzor added a commit that referenced this pull request Dec 23, 2024
This is targetted at #68.

After some preliminary refactorings to remove `Bwd` in #72, I realized
`brackets` and `within` were 90% the same, but resisted my first
attempts to combine them ;). Changing the contract on `within` (here
renamed `helper` and made local to `brackets`) allowed this to proceed.

Note the second commit makes explicit, using `Maybe....NonEmpty` an
invariant that in the first commit is just comments and
incomplete-pattern-matches; you may prefer the first way though.

---------

Co-authored-by: Craig Roy <craig.roy@cambridgequantum.com>
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.

1 participant