Created
January 23, 2010 18:23
-
-
Save retronym/284720 to your computer and use it in GitHub Desktop.
Limitation of Higher Kinded Inference
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 PartialApply1Of2[T[_, _], A] { | |
type Apply[B] = T[A, B] | |
} | |
trait Foo[M[_]] | |
def foo[M[_]]: Foo[M] = null | |
// Why can't the type parameter be inferred here? | |
// | |
// (fragment of pure-bind-monad-state.scala):9: error: polymorphic expression cannot be instantiated to expected type; | |
// found : [M[_]]this.Foo[M] | |
// required: this.Foo[[B]scala.collection.immutable.Map[Int,B]] | |
// foo: Foo[PartialApply1Of2[Map, Int]#Apply] | |
// ^ | |
// one error found | |
// !!! | |
// discarding <script preamble> | |
foo: Foo[PartialApply1Of2[Map, Int]#Apply] | |
// | |
// Explicitly passing the Type Constructor PartialApply1Of2[Map, Int]#Apply works. | |
// | |
foo[PartialApply1Of2[Map, Int]#Apply]: Foo[PartialApply1Of2[Map, Int]#Apply] | |
// | |
// The Type Constructor List[_] is inferred here. | |
// | |
foo: Foo[List] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment