Skip to content

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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tests/neg/higher-order-quoted-expressions.scala
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.
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would contain references to unbound variables in the current scope.

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.


// 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