Reading http://eed3si9n.com/learning-scalaz/Tagged+type.html and trying out sample code:
import scalaz._; import Scalaz._
sealed trait KiloGram
def KiloGram[A](a: A): A @@ KiloGram = Tag[A, KiloGram](a)
val mass = KiloGram(20.0)
2 * mass
according to the manual, should give 40.0, however, on Scala 2.11.2 I get:
scala> 2 * mass
<console>:17: error: overloaded method value * with alternatives:
(x: Double)Double <and>
(x: Float)Float <and>
(x: Long)Long <and>
(x: Int)Int <and>
(x: Char)Int <and>
(x: Short)Int <and>
(x: Byte)Int
cannot be applied to (scalaz.@@[Double,KiloGram])
2 * mass
^
then
2 * mass.asInstanceOf[Double]
works great.
Is it something 2.10 versus 2.11, or am I missing something? What is the meaning of insecure tags if I cannot use them like this (more) and must resort to explicit casts?
source
share