Created
December 21, 2009 09:52
-
-
Save retronym/260886 to your computer and use it in GitHub Desktop.
Contravariance + Implcicits kills kittens
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
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