Algebraic data type
Appearance
Algebraic Data Types (ADT) are a combined type formed from other data types. They are usually of two kinds: sum type or product type. The type can be divided into smaller parts, and this is called a subtype. Sum types can use one or the other of the subtypes it contains. Product types use all the subtypes it contains at the same time.
The number of elements of each subtype is counted. Sum types and product types do so differently. For a sum type with 3 subtypes (A, B, C) that each has 5 elements, the sum of them combined equals 15 (5 + 5 + 5). For the product type, it would equal 125 (5 * 5 * 5), the product of all combinations for every element in the subtype.
Uses
[change | change source]Some notable languages that use algebraic data types:
References
[change | change source]- ↑ "CppCon 2016: Ben Deane "Using Types Effectively"". Archived from the original on 2021-12-12 – via www.youtube.com.
- ↑ "Algebraic Data Types in Haskell". Serokell.
- ↑ "JEP 395: Records". OpenJDK.
- ↑ "JEP 409: Sealed Classes". OpenJDK.
- ↑ "Sealed Classes - Kotlin Programming Language". Kotlin.
- ↑ "Enums and Pattern Matching - The Rust Programming Language". doc.rust-lang.org. Retrieved 31 August 2021.
- ↑ "The Sum Type in V Programming Language!". rangakrish.