implicit def convert(a: Int with Tagged[KiloGram]): Int with Tagged[Gram] = (a * 1000).asInstanceOf[Int with Tagged[Gram]]
implicit def convert2(b: Int with Tagged[Gram]): Int with Tagged[KiloGram] = (a/1000).asInstanceOf[Int with Tagged[KiloGram]]
Brilliant. I'm just researching how units of measurements can be implemented in Scala. Would it be possible to make this also support unit conversions, e. g. Length * Time == Speed and comparable things?
@soc No I don't think it's up to that. The main problem is that eg. Int @@ T <: Int for any T, so the usual arithmetic operators are applicable (via simple subtype conformance of their arguments) and will have their ordinary result type (ie. Int). So, in particular, tagUser+tagCheckin compiles and has the value 36 : Int ... definitely not what you want for UoM.