QnaList > Groups > Scala-Internals > Mar 2016
faq

[scala-internals] How Does -Xstrict-inference Work? Why Does The "GADT Skolem" Compile With -Xstrict-inference?

//This topic was post in scala-user previously, but I think it's better for 
living in scala-internals.
HI, the follow codes are taken from 
http://stackoverflow.com/questions/17072185/understanding-the-limits-of-scala-gadt-support 
, 
  sealed trait A[-K, +V]
  case class B[+V]() extends A[Option[Unit], V]
  case class Test[U]() {
    def test[V](t: A[Option[U], V]) = t match {
      //1. with -Xstrict-inference: 
      //the following codes will compile
      //2. without -Xstrict-inference:
      //the following codes will not compile, and shows: 
      //constructor cannot be instantiated to expected type; found : B[V] required: A[Option[U],?V1] where type ?V1  null
    }
    def test2[V](t: A[Option[U], V]) = Test2.test2(t)
  }
  object Test2 {
    def test2[U, V](t: A[Option[U], V]) = t match {
      case B() => null // This works
    }
  }
According to scalac's help:"-Xstrict-inference" means "Don't infer known-unsound types". 
So based on http://scala-lang.org/files/archive/spec/2.11/08-pattern-matching.html#constructor-patterns , I think the above codes will NOT compile event with -Xstrict-inference.
BTW: I test with scala-2.11.8. 
Why? Any Help? Thansk.
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

asked Mar 31 2016 at 20:28

woshilaiceshide 's gravatar image



Related discussions

Tagged

Group Scala-internals

asked Mar 31 2016 at 20:28

active Mar 31 2016 at 20:28

posts:1

users:1

©2013 QnaList.com