Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type inference constraints should be carried along during search for chained implicits #2781

Closed
scabug opened this issue Dec 9, 2009 · 7 comments

Comments

@scabug
Copy link

scabug commented Dec 9, 2009

if implicit1: X[T] requires another implicit2: Y[T], the constraints (on T) that result from the search for implicit2 should be considered in the search for implicit1.

(right now the only communication goes on through undetparams, which does not track the typevars and their constraints)

@scabug
Copy link
Author

scabug commented Dec 9, 2009

Imported From: https://issues.scala-lang.org/browse/SI-2781?orig=1
Reporter: @adriaanm

@scabug
Copy link
Author

scabug commented Dec 9, 2009

@adriaanm said:
example at: http://gist.github.com/252311

@scabug
Copy link
Author

scabug commented Dec 21, 2009

@adriaanm said:
reason why we would like this: encoding the T <%< Traversable[U] generalized constraint: T <%< U depends on implicit value of T => U, but the search for the latter does not influence the bounds on the type vars in the former. see also #2811

@scabug
Copy link
Author

scabug commented Feb 26, 2010

@adriaanm said:
see #2673 for motivation

@scabug
Copy link
Author

scabug commented Apr 26, 2010

@adriaanm said:
the example on github compiles in the [http://github.com/adriaanm/scala/tree/topic/embeddings experimental embeddings branch], with one modification: Pure must be invariant in P:

class Scratch

import collection.generic.GenericCompanion

trait HasGenericCompanion[S[X] <: Traversable[X]] {
  def companion: GenericCompanion[S]
}

object HasGenericCompanion {
  lazy implicit val StreamHasCompanion: HasGenericCompanion[Stream] = new HasGenericCompanion[Stream] {
    def companion = Stream
  }

  lazy implicit val ListHasCompanion: HasGenericCompanion[List] = new HasGenericCompanion[List] {
    def companion = List
  }
}

trait Pure[P[_]] { // TODO: can we get this to work for Pure covariant in P?
  def pure[A](a: => A): P[A]
}

object Pure {
  implicit def HasGenericCompanionPure[S[X] <: Traversable[X]](implicit c: HasGenericCompanion[S]) = new Pure[S] {
    def pure[A](a: => A) = {
      c.companion.apply(a)
    }
  }
}

object Test {
implicitly[HasGenericCompanion[Stream]]

val pure = Pure.HasGenericCompanionPure(implicitly[HasGenericCompanion[Stream]])
val pure2 = Pure.HasGenericCompanionPure[Stream]

// this fails with:
//$$anon.this.Pure.HasGenericCompanionPure is not a valid implicit value for this.Pure[Stream] because:
//ambiguous implicit values:
// both lazy value ListHasCompanion in object HasGenericCompanion of type => this.HasGenericCompanion[List]
// and lazy value StreamHasCompanion in object HasGenericCompanion of type => this.HasGenericCompanion[Stream]
// match expected type this.HasGenericCompanion[S]
//(fragment of Scratch.scala):43: error: could not find implicit value for parameter e: this.Pure[Stream]
implicitly[Pure[Stream]]
}

@scabug
Copy link
Author

scabug commented Apr 26, 2010

@adriaanm said:
forgot: this is most closely related to #3346

@scabug
Copy link
Author

scabug commented Dec 13, 2011

@paulp said:
Adriaan, can you clarify the status of this ticket? The example below compiles everywhere I can find, so can we get a new and perhaps slightly more laser-targeted illustrative example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants