Created
September 11, 2017 15:00
-
-
Save metasim/b643b61acbf7961650d1744318ecda95 to your computer and use it in GitHub Desktop.
Figure out how to do overloading via more specific context bounds.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geotrellis.spark.{SpatialComponent, TemporalComponent} | |
object Test { | |
class Foo { | |
// ... | |
} | |
object Foo { | |
implicit val spatialComponent: SpatialComponent[Foo] = ??? | |
} | |
class Bar { | |
// ... | |
} | |
object Bar { | |
implicit val spatialComponent: SpatialComponent[Bar] = ??? | |
implicit val temporalComponent: TemporalComponent[Bar] = ??? | |
} | |
implicit class Doer[T: SpatialComponent](t: T) { | |
val ping = implicitly[SpatialComponent[T]].get(t) | |
} | |
implicit class DoerBetter[T: SpatialComponent: TemporalComponent](t: T) { | |
val ping = { | |
implicitly[SpatialComponent[T]].get(t) | |
implicitly[TemporalComponent[T]].get(t) | |
} | |
} | |
val foo = new Foo | |
val bar = new Bar | |
foo.ping | |
bar.ping // <- doesn't compile: | |
// Error:Error:line (33)type mismatch; | |
// found : A$A14.this.bar.type (with underlying type A$A14.this.Bar) | |
// required: ?{def ping: ?} | |
// Note that implicit conversions are not applicable because they are ambiguous: | |
// both method DoerBetter in class A$A14 of type [T](t: T)(implicit evidence$2: geotrellis.spark.SpatialComponent[T], implicit evidence$3: geotrellis.spark.TemporalComponent[T])A$A14.this.DoerBetter[T] | |
// and method Doer in class A$A14 of type [T](t: T)(implicit evidence$1: geotrellis.spark.SpatialComponent[T])A$A14.this.Doer[T] | |
// are possible conversion functions from A$A14.this.bar.type to ?{def ping: ?} | |
// bar.ping | |
// ^ | |
// Error:Error:line (33)value ping is not a member of A$A14.this.Bar | |
// bar.ping | |
// ^ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment