Skip to content

Instantly share code, notes, and snippets.

@ghik
Created March 18, 2017 15:59
Show Gist options
  • Save ghik/80fdf87a2410069ea652e969fb59b8d1 to your computer and use it in GitHub Desktop.
Save ghik/80fdf87a2410069ea652e969fb59b8d1 to your computer and use it in GitHub Desktop.
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