Unable to use extensions for NewtypeF
ajaychandran opened this issue · comments
Ajay Chandran commented
The following example fails to compile.
import zio.prelude._
type PropF[+A] = PropF.Type[A]
object PropF extends NewtypeF {
implicit class PropInt(private val self: Type[Int]) extends AnyVal {
def next: Type[Int] =
wrap(unwrap(self) + 1)
}
implicit class PropNumeric[+A](private val self: Type[A]) extends AnyVal {
def increment(implicit N: Numeric[A]): Type[A] =
wrap(N.plus(unwrap(self), N.one))
}
}
val pf1: PropF[Int] = PropF(1)
val pf2: PropF[Int] = pf1.next // compile error: value next is not a member of Playground.PropF[Int]
val pf3: PropF[Int] = pf1.increment // compile error: value increment is not a member of Playground.PropF[Int]
Is this usage incorrect/unsupported?
Adam Fraser commented
@ajaychandran You just need to do import PropF._
.
Ajay Chandran commented
Thanks @adamgfraser.
Adding an import statement does resolve the issue but it impacts usability adversely.
I am trying to define new operators so that no extra imports are required (this works for Newtype
instances). Is it not possible to do the same with NewtypeF
?