Skip to content

Instantly share code, notes, and snippets.

@piotrga
Created December 25, 2011 18:13
Show Gist options
  • Save piotrga/1519565 to your computer and use it in GitHub Desktop.
Save piotrga/1519565 to your computer and use it in GitHub Desktop.
Repr
trait CurrencyLike[Repr <: CurrencyLike[Repr]]{
val value : Double
def make(d:Double) : Repr
def +(x: Repr) = make(x.value + value)
}
class USD(val value: Double) extends CurrencyLike[USD] { def make(d: Double) = new USD(d) }
class EUR(val value: Double) extends CurrencyLike[EUR] { def make(d: Double) = new EUR(d) }
def plus[T <: CurrencyLike[T]](c1: T, c2:T) : T = c1 + c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment