▲ | zdragnar 6 hours ago | |
I have this mental block that keeps me forgetting which is which when discussing sum and product types. I have to go back to thinking of them as operations on sets. Almost certainly a lack of formal education in maths higher level than simple calculus, but "unions" and "interface" or whatever the latter might be called in the language of choice is just so much easier to remember. | ||
▲ | ndriscoll 4 hours ago | parent | next [-] | |
* is and, + is or. This agrees with Boolean algebra, so you can think in terms of a single bit. If you can also remember that functions A->B are exponentials B^A, then you can do a quick check that everything lines up: C^(A+B) = C^A*C^B. A function that handles A or B is the same as a function that handles A and a function that handles B. | ||
▲ | nutjob2 6 hours ago | parent | prev [-] | |
It's usually described as tagged unions and records, and the easy way to remember it by thinking about how many different values they can contain. Given that each type represents some number of possible values, the number of values for the unions is the sum of values for each allowable type and for records its the product of each field type. |