Skip to content

Allow generically sealed expressions #5651

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

Closed

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Dec 20, 2018

It is useful when quoting code that comes from sealed reflected Terms.

def let[T](s: Sealed)(body: Expr[s.Tpe] => Expr[T]): Expr[T] = '{
  val x: ~s.tpe = ~s.expr
  ~body('(x))
}
let(term.seal)(...)

It is useful when quoting code that comes from sealed reflected `Term`s.

```
def let[T](s: Sealed)(body: Expr[s.Tpe] => Expr[T]): Expr[T] = '{
  val x: ~s.tpe = ~s.expr
  ~body('(x))
}
let(term.seal)(...)
```
@liufengyun
Copy link
Contributor

Introducing a new concept is a big change, I think we need to discuss in the meeting. From the perspective of macro authors, I think the cognitive burden it causes out-weighs the safety guarantee it brings.

I'm fine with more experiments, but it would be really nice to have a few ready and friendly constructors that macro authors can use right now for real-world macros -- not the possibility to construct such APIs in a 3rd-party library in the future. Otherwise, the macro story for macro authors continues to be half-baked. I think that is the main purpose of porting ScalaTest, and one motivation for my work on ScalaTest.

@nicolasstucki
Copy link
Contributor Author

This is not really a new concept. It is a cleanup of the seal API. It splits the two steps that seal previously did internally and allows the user to interact.

We do need to be able to create any tree possible TASTy tree. But tree constructors cannot be friendly to users by design, they may be easy to call but will have no static guarattees. Tree constructors also require a lot of knowage about the system which makes them an low level expert API, most users should be discuraged from using it directly if the same can be expressed in terms of quotes and splices.

@nicolasstucki nicolasstucki self-assigned this Dec 26, 2018
@milessabin
Copy link
Contributor

milessabin commented Jan 7, 2019

My concern is that Sealed is basically just an encoding of an existential over what I've called TypedExpr below,

final case class TypedExpr[T](e: Expr[T], t: Type[T])

class Exists[F] {
  type Tpe
  val value: F[Tpe]
}  

object Sealed {
  def apply[T](expr: Expr[T])(implicit tpe: Type[T]): Exists[TypedExpr] =
    new Exists {
      type Tpe = T
      val value = TypedExpr(expr, tpe)
    }
}

@Blaisorblade
Copy link
Contributor

@milessabin That’s a possible alternative, no opinion on using it here or not.
#4353 (comment) has another proposal for Exists; that thread discusses the design and questions with overloads for other arities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants