refactor: avoid Bwd in within and brackets(Worker)#72
Closed
acl-cqc wants to merge 5 commits intorefactor/parser-wcfrom
Closed
refactor: avoid Bwd in within and brackets(Worker)#72acl-cqc wants to merge 5 commits intorefactor/parser-wcfrom
Bwd in within and brackets(Worker)#72acl-cqc wants to merge 5 commits intorefactor/parser-wcfrom
Conversation
5523589 to
25f19d8
Compare
Collaborator
Author
|
Closing in favour of #73 |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 simplifieswithina bit (no need to passacc), and simplifiesbracketsWorkersubstantially (makingbrackets==bracketsWorker).Individual commits compile so you can see the steps.
It's a shame not to be able to combine
withinandbracketsbecause they are very very similar (the| Just b <- opener (_tok t) = docase in particular); I tried using aMaybe (FC, BracketType)forctxand that almost did it but doesn't copy withwithinneeding extra return values :-(. (One could have aMaybereturn 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)