In Scala, why doesn't Unit
extend the Product
trait just like the Tuple
* classes and case classes (including the "empty" ones, like in case class Empty()
, and case objects)?
Unit
(the unit value ()
to be more specific) definitely stands as the empty product and tuple. It is used this way in shapeless, for example.
Unit is not analogous to to an empty collection, so it doesn't make sense to make it a product of arity zero. Even though a Product0 wouldn't contain any data, it would still define behaviour via the productElement and productIterator methods.
The goal of Unit is to represent the absence of any behaviour or data beyond the bare minimum defined in Object. In fact, the getClass() function returns null to indicate that it has no type, no by definition it should have no metadata associated with it.
If you were to make Unit extend Product, then it would violate the concept of "no type".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With