This seems somewhat redundant, but the A -> C
conversion is exactly what you have to provide. The reason is that if implications are rare, transition chains are also rare and you probably want to. But if implications are common, most likely you can turn anything into anything (or, if you add a convenient expression implicitly, suddenly all kinds of behavior will change because you opened different paths for implicit conversion).
You may have a Scala implicit conversion chain for you, however, if you specify that you need to do this. The key is to use generics with <%
, which means "can be converted to." Here is an example:
class Foo(i: Int) { def foo = i } class Bar(s: String) { def bar = s } class Okay(b: Boolean) { def okay = b } implicit def to_bar_through_foo[T <% Foo](t: T) = new Bar((t: Foo).foo.toString) implicit def to_okay_through_bar[U <% Bar](u: U) = new Okay((u: Bar).bar.length < 4) scala> (new Foo(5)).okay res0: Boolean = true
source share