Created
December 25, 2011 18:13
-
-
Save piotrga/1519565 to your computer and use it in GitHub Desktop.
Repr
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
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