Scalaz unboxed tagged type does not automatically decompress

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?

+4
source share
1 answer

OK, it turns out this was changed in Scalaz 7.1 to https://github.com/scalaz/scalaz/pull/693 .

, , , "" :

scala> trait Kg
scala> val Kg = Tag.of[Kg]
scala> val mass = Kg(15.0)
scala> 3 * Kg.unwrap(mass)
res0: Double = 45.0

S11001001, ceedubs, tpolecat adelbertC #scalaz .

+7

All Articles