Skip to content

GADT inference suffer from polymorphic functions #6856

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
DoSOfRedRiver opened this issue Jul 15, 2019 · 1 comment
Closed

GADT inference suffer from polymorphic functions #6856

DoSOfRedRiver opened this issue Jul 15, 2019 · 1 comment

Comments

@DoSOfRedRiver
Copy link

minimized code

trait Smt[F[_], A] {
  def fa: F[A]

  def smt[G[_]](f: [X] => F[X] => G[X]): G[A] = f(fa)
}

enum Console[A] {
  case ReadLine extends Console[String]
  case PrintLine extends Console[Unit]
}

val smtListInts = new Smt[Console, String] {
  def fa = Console.ReadLine
}

val res: List[String] = smtListInts.smt[List]([X] => (con: Console[X]) => con match {
  case Console.ReadLine =>
    List("string")
  case Console.PrintLine =>
    List(())
})

expectation

I expect compiler to infer [X] type, but instead, I have to cast results manually:

val res: List[String] = smtListInts.smt[List]([X] => (con: Console[X]) => con match {
  case Console.ReadLine =>
    List("string").asInstanceOf[List[X]]
  case Console.PrintLine =>
    List(()).asInstanceOf[List[X]]
})
@abgruszecki
Copy link
Contributor

Thanks for reporting this issue!

We already track it as #5828, so I'm going to close this one.

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

No branches or pull requests

2 participants