An experimental implementation of Nominal representation based backend for unbound#42
Open
hengchu wants to merge 1 commit intosweirich:masterfrom
Open
An experimental implementation of Nominal representation based backend for unbound#42hengchu wants to merge 1 commit intosweirich:masterfrom
hengchu wants to merge 1 commit intosweirich:masterfrom
Conversation
Nominal2: finishing up Alpha and working on Subst Nominal2: implemented Subst Nominal: renaming the implementation files Nominal: cleaned up testsuite Nominal: adding the missing test file removing cruft
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.
For this semester's independent studies, I have worked on profiling and implementing a new backend of the unbound library.
My work consists of 3 parts:
LocallyNamelessunboundNominalbackendLocallyNamelessbackend andNominalbackendThe nominal implementation preserves most of the existing interface of unbound, although all of the typeclasses used are redefined so that nominal unbound is not constrained by the existing interface when it does not apply to nominal unbound.
This implementation uses the same generic programming techniques to provide support for user defined datatypes of language constructs. For me, understanding how generic programming with overridable behavior was a non-trivial part of the project. I found the RepLib paper and the extended version of SYB to be extremely helpful.
As part of the journey on understanding generic programming, I also briefly compared the generic programming interface exposed by
RepLibandGHC.Generics, and I found the combinators exposed in Generics.RepLib.Aux to be invaluable when traversing data structures generically. I also became more aware of the benefits of existential types while trying to understand how RepLib represents heterogeneous lists, and this helped me understand the materials presented in PFPL better.For the semantics of the nominal interface, I referred to the Binders Unbound paper and recreated the
Rec,RebindandEmbedpattern type constructors and theBindbinder type constructor. A significant effort in the implementation was devoted to theAlphatypeclass and its instantiation for each of the type constructors mentioned above. I have tested the behavior of these implementations with a simply typed lambda calculus extended with mutually recursive let expressions, but I have not yet produced any formal proofs of their correctness. TheSubsttypeclass and its generic implementation provides capture-avoiding substitution.The idioms for working with locally nameless unbound carry over to nominal unbound, since minimizing the effort between switching these two implementations was also part of the goal.
In terms of exploring the design space of DSL for binding specifications, I have also studied FreshML, Cαml and FreshLib. These papers were really helpful for observing what difficulties each design choice face and where to balance the power/weight ratio.
In terms of the performance of nominal unbound, currently it is up to 4x slower than the locally nameless implementation on large terms (terms with over 100 nested patterns and terms). However, there are a few optimization opportunities I can take as future work:
Bindto speed up free variable calculuation, which is helpful when we need to perform fresheningBindand apply them lazily to the variablesmatchfor alpha equivalence of bindersIn particular, the first optimization could potentially help with the performance of locally nameless unbound as well since free variable calculation will be possible in constant time.
The last optimization opportunity was recognized when I read Nominal Matching and Alpha-Equivalence. In the case of linear patterns, this paper presents an algorithm that runs in log-linear time.