So it's my understanding there are two types of Algebraic Data Types (ADTs). For the case of Option[T]
in Scala or Optional<T>
in Java, would this be an example of a sum type or a product type?
Asked
Active
Viewed 374 times
1

uh_big_mike_boi
- 3,350
- 4
- 33
- 64
-
2I'm pretty sure you can figure it out if you consider that an `Optional
` is either a `T` or no `T`. – molbdnilo Nov 26 '17 at 02:40 -
Because it is fixed ok – uh_big_mike_boi Nov 26 '17 at 02:45
1 Answers
2
Defining the Option[T]
type in Haskell makes it clear that it's a sum type.
data Option t = None | Some t
Values of type Option t
can be one of 2 things:
None
Some t
So Option[T]
and Optional<T>
both take a type T
and then add 1 more possible value (None
).
For fun, we can also translate this ADT into an algebraic equation:
Option(t) = 1 + t
To see why, see this question: Abusing the algebra of algebraic data types - why does this work?

4castle
- 32,613
- 11
- 69
- 106