Created
February 5, 2012 15:35
-
-
Save soc/1746104 to your computer and use it in GitHub Desktop.
Problem with implicits ...
This file contains hidden or 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
| object UnitsEx2 { | |
| case class Quantity[T: Numeric](value: T) { | |
| private val num = implicitly[Numeric[T]] | |
| def *(m: Quantity[T]) = Quantity[T](num.times(value, m.value)) | |
| } | |
| implicit def measure[T: Numeric](v: T): Quantity[T] = Quantity[T](v) | |
| implicit def numericToQuantity[T: Numeric](v: T): QuantityConstructor[T] = new QuantityConstructor[T](v) | |
| class QuantityConstructor[T: Numeric](v: T) { | |
| def m = Quantity[T](v) | |
| } | |
| } | |
| import UnitsEx._ | |
| (1 m) * 1 // Works | |
| 1 * (1 m) // Works |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment