http://eed3si9n.com/learning-scalaz/Tagged+type.htmlを読み、サンプル コードを試してみます。
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
ガイドによると、生成する必要があります40.0
が、Scala 2.11.2 では次のようになります。
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
^
一方
2 * mass.asInstanceOf[Double]
うまく動作します。
それは 2.10 対 2.11 のものですか、それとも何か不足していますか? このように (もう) 使用できず、明示的なキャストに頼らなければならない場合、ボックス化されていないタグ付きタイプのポイントは何ですか?