Prototype 'out' type variables that mimic associated types#25
Merged
Conversation
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.
First, I introduced
@Outwhich annotates a type parameter in a type class. It denotes that a witness for this type class outputs a type through the respective type argument.My goal was to enable an encoding of GHC Generics, without the need for type families:
And, for starters, with a very basic type-level representation:
Witnesses would then look like:
The API is really simple. But then we have a couple of implementation challenges to tackle:
@Out.Treeabove, so that:Let's tackle (2) first.
First, I introduced a wrapper type that introduces laziness for witness constraints:
It needs to be applied, for example, when handling the
K1type representation constructor, which may or may not introduce recursion. For example:Then, I updated the recursive resolution algorithm:
Lazyconstructor for theParsedTypeADT. This marks the request for lazy resolution by the client.Lazyon the head, then:Lazyconstructor has been seen before, then emit aLazyLookupnode,LazyWrapnode.Lazy<A>, even though we have a concrete object.Now, onto tackling (1).
At a high level:
@Out-annotated type parameters are annotated in theParsedTypestructure somehow.Outconstructor. (Note: unification ignoresOutnodes.)(provides: List<Var>, expects: List<Var>).Outconstructors go inprovidesand the rest go underexpects.TreeMap<Integer, List<Constraint>>.)