News for hackers. Stuff that matters.
Re:Java 21 makes me like Java again by aranchelk on Saturday September 16, 2023 @06:39PM (#37539504)
> Why do we call them product types anyway?

Answer in the piece is not wrong, but put more intuitively and succinctly: the total number of possible value (inhabitants) in a product type is the product of the quantity of inhabitants of the constituent types.

Replace the “product”s with “sum”s and it works too.

Interestingly, the total number of unique functions (judged only in terms of input and output) from a -> b can be found by exponentiation, (inhabitants of b) ^ (inhabitants of a).

Re:Java 21 makes me like Java again by wscp-dev on Sunday September 17, 2023 @02:03AM (#37541981)
Ill add that in, somehow forgot about that golden bit of info
Re:Java 21 makes me like Java again by trenchgun on Sunday September 17, 2023 @03:32AM (#37542451)
>Answer in the piece is not wrong, but put more intuitively and succinctly: the total number of possible value (inhabitants) in a product type is the product of the quantity of inhabitants of the constituent types.

More intuitively and succintly: product type is equivalent to a cartesian product of sets

Re:Java 21 makes me like Java again by tubthumper8 on Sunday September 17, 2023 @01:22PM (#37547363)
Maps (and lists) are other examples of exponential types. Intuitively this should make sense that these are the same as functions because any pure function could be (theoretically) replaced with a map lookup of pre-computed values. In this context, list is a special map where the keys are integers.

Writing it out mathematically, given a List of Bool, the left-hand side is the number of elements and the right-hand side is the total possibilities.

- 0 : 1

- 1 : 2

- 2 : 4

- 3 : 8

- 4 : 16

- 5 : 32

and so on