This page is no longer maintained — Please continue to the home page at

Broken implicit resolution

No replies
Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Hi, somehow I broke some code of mine that uses the CanBuildFrom kind of pattern --- using implicit type classes to determine the behavior of a method as well as its return type based on the types passed to it.
The last line of the following code doesn't compile. If someone can change around the definition of CanFlatMapSignal (and the type arguments to flatMap) so that it works, I'd really appreciate it.
trait DeltaSeq[+A]

class Signal[+T] {
  def flatMap[U, S[_], S2[_]](f: T => S[U])(implicit canFlatMapSignal: CanFlatMapSignal[U, Signal, S[U], S2[U]]): S2[U] = canFlatMapSignal.flatMap(this, f)

class SeqSignal[+T] extends Signal[DeltaSeq[T]]

class BufferSignal[T] extends SeqSignal[T]

trait CanFlatMapSignal[U, -Parent[_], -FunRet, +Ret] {
  def flatMap[T](parent: Parent[T], f: T => FunRet): Ret

implicit def canFlatMapSignal[U, S <: Signal[U]]: CanFlatMapSignal[U, Signal, S, Signal[U]] = new CanFlatMapSignal[U, Signal, S, Signal[U]] {
  def flatMap[T](parent: Signal[T], f: T => S): Signal[U] = sys.error("todo")

val v = new BufferSignal[Int]

v.flatMap(x => new BufferSignal[Int])

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland