Created
March 18, 2017 15:59
-
-
Save ghik/80fdf87a2410069ea652e969fb59b8d1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 abstract class Stuff[F[_], +A] | |
case class Suspend[F[_], A](a: () => F[A]) | |
extends Stuff[F, A] | |
def extract[F[_], A](source: Stuff[F, A]): Suspend[F, A] = | |
source match { | |
case ref @ Suspend(_) => ref.asInstanceOf[Suspend[F,A]] | |
} | |
import scala.collection.mutable | |
val s = mutable.Set.empty[String] | |
val stuff: Stuff[mutable.Set,Any] = Suspend(() => s) | |
val s2 = extract(stuff).a() | |
s2 += 123 | |
s.head | |
//java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String | |
// ... 29 elided |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment