Given the following Algebraic Data Type:
scala> sealed trait Person
defined trait Person
scala> case class Boy(name: String, age: Int, x: String) extends Person
defined class Boy
scala> case class Girl(name: String, age: Int, y: Boolean) extends Person
defined class Girl
Note - I know that it's not a Recursive Type - there's no recursion involved.
So, is this a Sum
or Product Type
? Why?
In this case,
Person
can be considered as a sum type since an instance of it is eitherBoy
orGirl
.Boy
(orGirl
) is a product type since an instance ofBoy
is a combination of typeString
,Int
, andString
.Here is a very nice article about this "hybrid" case Algebraic Data Types in Scala