Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyricallogical/1da1331b0a5326fb143b to your computer and use it in GitHub Desktop.
Save lyricallogical/1da1331b0a5326fb143b to your computer and use it in GitHub Desktop.
extractor pattern で skolem 型変数の扱いが意味わからんという話。
import scala.language.higherKinds
sealed trait Base[F[_]] { // all compilation is succeeded if F' kind is *
def a: String
}
case class Ctor[F[_]](a: String) extends Base[F]
abstract class Etor[F[_]] extends Base[F] {
def f(q: Base[F]): String = q match {
case Ctor(fa) => fa // NP
case Etor(fa) => fa // error! why???
// exractor_with_skolem.scala:10: error: pattern type is incompatible with expected type;
// found : Etor[F(in method unapply)]
// required: Base[F(in class Etor)]
// case Etor(fa) => fa
// ^
// case etorr: Etor[F] => etor.a // NP
}
}
object Etor {
def unapply[F[_]](node: Etor[F]): Option[String] = {
if (node eq null) None else Some(node.a)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment