> we turn our attention to the dual of records – variants.
How is this the case, can someone give me an example?
How is this the case, can someone give me an example?
A variant is a logical or. A pet is a dog or a cat.
And and or are duals.
Much more in the "Algebraic data types" chapter at https://scalawithcats.com/
Does that answer it?
For example: A record type {x:X, y:Y} is a supertype of {x:X, y:Y, z:Z} (all values of the second can stand in as values of the first), while a variant type x:X | y:Y is a subtype of x:X | y:Y | z:Z (all values of the first can stand in as values of the second).
The sibling comments refer to AND and OR (which isn't accurate, as variants are really XOR), or to product and sum types, but that doesn’t demonstrate the actual duality.
https://www.cs.princeton.edu/courses/archive/fall05/cos441/n...