Skip to content

Instantly share code, notes, and snippets.

@soc
Created February 5, 2012 15:35
Show Gist options
  • Select an option

  • Save soc/1746104 to your computer and use it in GitHub Desktop.

Select an option

Save soc/1746104 to your computer and use it in GitHub Desktop.
Problem with implicits ...
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