Skip to content
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

Alternative syntax for polymorphic lambdas (for Shapeless) #138

Open
yangzai opened this issue Mar 11, 2020 · 3 comments
Open

Alternative syntax for polymorphic lambdas (for Shapeless) #138

yangzai opened this issue Mar 11, 2020 · 3 comments

Comments

@yangzai
Copy link

yangzai commented Mar 11, 2020

Currently kind-projector allows

val g = λ[Id ~> Option].run(x => Some(x))

to be rewritten as

val g = new (Id ~> Option) {
  def run[A](x: Id[A]): Option[A] = Some(x)
}

I was wondering if there could be an alternative syntax that rewrites to

object g extends (Id ~> Option) {
  def apply[A](x: Id[A]): Option[A] = Some(x)
  
// if possible it should allow rewrite to other method names as well:
//  def run[A](x: Id[A]): Option[A] = Some(x)
}

in situations where the singleton type g.type is required.

i.e. in Shapeless

the[Case1.Aux[g.type, Id[Int], Option[Int]]]

should compile.

@SethTisue
Copy link
Member

this suggestion doesn't seem to have any attracted much interest. should we leave the ticket open?

@dwijnand
Copy link
Contributor

In

val g = new (Id ~> Option) {
  def run[A](x: Id[A]): Option[A] = Some(x)
}

The static type is Id ~> Option. If you need a singleton type have you seen if the following works?

val gDefn = new (Id ~> Option) {
  def run[A](x: Id[A]): Option[A] = Some(x)
}
val g: gDefn.type = gDefn
the[Case1.Aux[g.type, Id[Int], Option[Int]]]

@yangzai
Copy link
Author

yangzai commented Mar 23, 2021

@dwijnand nope. I still can't get it to work. I'm testing with:

object Shape extends App {
  import shapeless._
  import shapeless.PolyDefns._

  object G extends (Id ~> Option) {
    def apply[A](x: Id[A]): Option[A] = Some(x)
  }

  val gDefn = new (Id ~> Option) {
//    def run[A](x: Id[A]): Option[A] = Some(x)
    override def apply[T](x: Id[T]): Option[T] = Some(x)
  }
  val g: gDefn.type = gDefn

  the[Case1.Aux[G.type, Id[Int], Option[Int]]] //compiles
  the[Case1.Aux[g.type, Id[Int], Option[Int]]] //does not compile
  the[Case1.Aux[gDefn.type, Id[Int], Option[Int]]] //does not compile
}

Error message:

could not find implicit value for parameter t: shapeless.PolyDefns.Case1.Aux[Shape.g.type,shapeless.Id[Int],Option[Int]]
  the[Case1.Aux[g.type, Id[Int], Option[Int]]] //does not compile

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

No branches or pull requests

3 participants