Closed
Description
Normally I could write an anonymous function and the argument type could be inferred based on the expected type. For example, if I defined type Set[A] = A => Boolean
then I could write def singleton[A](a: A): Set[A] = _ == a
and the type of _
would be inferred as A
. However, if I define Set
as opaque
and try to do this in the type companion it doesn't work. I have to specify the type of the argument explicitly, which seems unnecessary and inconsistent given that within the type companion the opaque type and its definition are supposed to be the same thing.
object TypeAlias {
type Set[A] = A => Boolean
object Set {
def singleton[A](a: A): Set[A] = _ == a // Works
}
}
object OpaqueType {
opaque type Set[A] = A => Boolean
object Set {
//def singleton[A](a: A): Set[A] = _ == a // Does not compile
def singleton0[A](a: A): Set[A] = (_: A) == a // Works
}
}
Metadata
Metadata
Assignees
Labels
No labels