Skip to content

Instantly share code, notes, and snippets.

@retronym
Created December 21, 2009 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retronym/260886 to your computer and use it in GitHub Desktop.
Save retronym/260886 to your computer and use it in GitHub Desktop.
Contravariance + Implcicits kills kittens
trait FoldRight[-M[_]]
{
implicit val StreamFoldRight: FoldRight[Stream] = new FoldRight[Stream] {}
implicit val IterableFoldRight: FoldRight[Iterable] = new FoldRight[Iterable] {}
assert(implicitly[FoldRight[Stream]] eq IterableFoldRight) // want StreamFoldRight
}
{
abstract class Low {
implicit val IterableFoldRight: FoldRight[Iterable] = new FoldRight[Iterable] {}
}
object FoldRight extends Low {
implicit val StreamFoldRight: FoldRight[Stream] = new FoldRight[Stream] {}
}
import FoldRight._
//assert(implicitly[FoldRight[Stream]] eq IterableFoldRight)
// UNCOMMENT FOR:
// error: ambiguous implicit values:
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment