News for hackers. Stuff that matters.
Re:Structuring Arrays with Algebraic Shapes by FjordWarden on Saturday June 28, 2025 @02:58AM (#44402795)
> we turn our attention to the dual of records – variants.

How is this the case, can someone give me an example?

Re:Structuring Arrays with Algebraic Shapes by noelwelsh on Saturday June 28, 2025 @03:02AM (#44402803)
Records are a logical and. A cat is a name and an age and a color, for 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?

Re:Structuring Arrays with Algebraic Shapes by FjordWarden on Saturday June 28, 2025 @03:34AM (#44402888)
Ok, sum types and product types
Re:Structuring Arrays with Algebraic Shapes by noelwelsh on Saturday June 28, 2025 @04:45AM (#44403196)
Yes.
Re:Structuring Arrays with Algebraic Shapes by suspended_state on Saturday June 28, 2025 @05:11AM (#44403289)
Records are product types. Variants are sum types.

https://www.cs.princeton.edu/courses/archive/fall05/cos441/n...

Re:Structuring Arrays with Algebraic Shapes by layer8 on Saturday June 28, 2025 @08:06AM (#44404075)
A record is "for all labels, I have a corresponding value". A variant is "there exists (exactly) one label for which I have a corresponding value". They are similar to ∀ and ∃ in that way, which are logical duals.