-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add draft as regression tests #14413
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
Merged
nicolasstucki
merged 2 commits into
scala:main
from
dotty-staging:draft-higher-order-expressions
Feb 7, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Draft of higher order expressions | ||
// --------------------------------- | ||
// A higher order expression is a an expression that may contain unbound variables. | ||
// Unbound variables are listed as arguments of the type lambda of the expression. | ||
// Splicing can only be done on Expr[_ <: Any]. | ||
// `apply methods on higher order expression provide a way to replace the unbound variables. | ||
|
||
// This can be used for HOAS quoted patterns to not return a lambda (see HOAS patterns section in https://infoscience.epfl.ch/record/288718?ln=en). | ||
// The use would be the same as each higher order expression would have an apply method. | ||
// But as it would be an expression, the expression would showable. | ||
// The expression could also be directly transformed into a Term of the reflection API. | ||
|
||
// Question: How to extend this to allow unbound type (Type) in the expression? | ||
|
||
class Expr[+T <: AnyKind] | ||
object Expr: | ||
extension [T, R](hoe: Expr[[_ >: T <: T] =>> R]) def apply(x1: Expr[T]): Expr[R] = ??? | ||
extension [T1, T2, R](hoe: Expr[[_ >: T1 <: T1, _ >: T2 <: T2] =>> R]) def apply(x1: Expr[T1], x2: Expr[T2]): Expr[R] = ??? | ||
// Are lower bounds in lambda parameters necessary? | ||
// How could this be generalized to n arguments? | ||
|
||
|
||
def `'`[T](e: T): Expr[T] = ??? | ||
def `$`[T](e: Expr[T]): T = ??? | ||
|
||
def f(): Unit = | ||
val e: Expr[Int] = ??? | ||
val hoe1: Expr[[T >: Int <: Int] =>> Int] = ??? // assumed to come from HOAS pattern with one unbound variable of type Int | ||
val hoe2: Expr[[T1 >: Int <: Int, T2 >: Int <: Int] =>> Int] = ??? // assumed to come from HOAS pattern with 2 unbound variables of type Int | ||
val e2: Expr[Int] = hoe1(e) | ||
val e3: Expr[Int] = hoe2(e, e) | ||
|
||
{ | ||
`$`{e} | ||
`$`{e2} | ||
`$`{e3} | ||
`$`{hoe1(e)} | ||
`$`{hoe2(e, e)} | ||
`$`{hoe1} // error: Found: Expr[[T >: Int <: Int] =>> Int]), Required: Expr[Any] // may contain references to 1 unbound variable | ||
`$`{hoe2} // error // may contain references to 2 unbound variables | ||
} | ||
`'`{1} | ||
`'`{`$`{e}} | ||
`'`{??? : ([T >: Int <: Int] =>> Int)} // error: Missing type parameter for [T >: Int <: Int] =>> Int // not a valid quote literal expression |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean, we could have a Term with holes? How would that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not no holes in the sense of the
Hole
AST. It would contain references to unbound variables in the current scope. We should probably also have a way to list the symbols of those variables to be able to identify them when reflecting on the AST. I still need to figure out what is the best way to encode this internally.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what can we do with such a term? I thought translating from an Expr to a Term should always produce a valid hygiienic tree.