Skip to content

Instantly share code, notes, and snippets.

@retronym
Created January 23, 2010 18:23
Show Gist options
  • Save retronym/284720 to your computer and use it in GitHub Desktop.
Save retronym/284720 to your computer and use it in GitHub Desktop.
Limitation of Higher Kinded Inference
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