Created
February 6, 2016 16:13
-
-
Save lyricallogical/1da1331b0a5326fb143b to your computer and use it in GitHub Desktop.
extractor pattern で skolem 型変数の扱いが意味わからんという話。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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