this post was submitted on 11 Apr 2024
10 points (91.7% liked)
No Stupid Questions (Developer Edition)
896 readers
1 users here now
This is a place where you can ask any programming / topic related to the instance questions you want!
For a more general version of this concept check out !nostupidquestions@lemmy.world
Icon base by Lorc under CC BY 3.0 with modifications to add a gradient
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
In higher math, sum and product don't necessarily have anything to do with the sum and product we know, but are just operations with certain properties.
In this case, a product is just a collection of multiple types, e.g. a tuple. An example would be a pair of index (integer) and value (e.g. a string) when iterating over a list.
A sum on the other hand is more of an
or
. In many languages, this is called something like an enum. If for example, your program should support both integers and floating point numbers, you would need the sum typeint | float
.Union types and sum types are two distinct concepts.
Int | Int
is the same type asInt
, butInt + Int
is not the same type asInt
.