April 2018
Intermediate to advanced
396 pages
11h 8m
English
Hybrid algebraic data types represent a combination of the sum and product ones we described previously. This means that we can have specific value constructors, but these value constructors also provide parameters in order to wrap other types.
Let's see an example. Imagine we are writing a drawing application:
sealed abstract trait Shapecase class Circle(radius: Double) extends Shapecase class Rectangle(height: Double, width: Double) extends Shape
We have different shapes. The preceding example shows a sum ADT because we have the specific Circle and Rectangle value constructors. Also, we have a product ADT because the constructors take extra parameters.
Let's expand our classes a bit. When drawing our shapes, we need to know ...
Read now
Unlock full access