Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-6895

Type class instance can't be found for type lambda, but type alias works


    • Type: Bug
    • Status: CLOSED
    • Priority: Major
    • Resolution: Not a Bug
    • Affects Version/s: Scala 2.9.2, Scala 2.10.0
    • Fix Version/s: None
    • Component/s: Compiler (Misc)
    • Labels:


      Suppose we have the following two type classes, an instance of the first for an either-like trait, and a way of building instances of the first from some specific instances of the second:

      trait Foo[F[_]]
      trait Bar[F[_], A]
      trait Or[A, B]
      implicit def orFoo[A] = new Foo[({type L[X] = Or[A, X]})#L] {}
      implicit def barFoo[F[_]: Foo] = new Foo[({type L[X] = Bar[F, X]})#L] {}

      Now we can define a couple of type aliases:

      type StringOr[X] = Or[String, X]
      type BarStringOr[X] = Bar[StringOr, X]

      And get an instance of our first type class:

      scala> implicitly[Foo[BarStringOr]]
      res1: Foo[BarStringOr] = $anon$1@4b5a1133

      But when we try the same thing with a type lambda, we get an error:

      scala> implicitly[Foo[({type L[X] = Bar[StringOr, X]})#L]]
      <console>:14: error: could not find implicit value for parameter e: Foo[[X]Bar[[X]Or[String,X],X]]
                    implicitly[Foo[({type L[X] = Bar[StringOr, X]})#L]]

      I asked a question on Stack Overflow about this last week, but haven't gotten any answers, and I haven't been able to find any previous issues that address the problem (a comment on my question points to this open improvement, but I don't see how this could be a type constructor inference issue).


          Issue Links



              • Assignee:
                retronym Jason Zaugg
                travisbrown Travis Brown
              • Votes:
                0 Vote for this issue
                9 Start watching this issue


                • Created: