News for hackers. Stuff that matters.
Re:Where does the name "algebraic data type" come from? by perihelions on Wednesday July 31, 2024 @11:48AM (#41120238)
This works with function types too. You can get a hint that objects with signature A -> (A -> A) have an isomorphism with objects of signature (A × A) -> A, by observing that the cardinalities are equal as algebraic expressions, ( |A|^|A| )^|A| = |A|^( |A|*|A| ). That one's just "currying" [0].

[0] https://en.wikipedia.org/wiki/Currying

Re:Where does the name "algebraic data type" come from? by Sharlin on Wednesday July 31, 2024 @12:25PM (#41120609)
Yep, that’s one of the more mind-blowing "tricks" as it were. Maybe less moreso, but still nifty, is that

  |T -> bool| = |bool|^|T| = 2^|T|
…which also happens to be the number of subsets of a set of size |T|. And indeed that’s what a predicate function is, a subset-generator; for every subset there is exactly one predicate that picks the members of that subset from the larger set.
Re:Where does the name "algebraic data type" come from? by gpderetta on Wednesday July 31, 2024 @01:19PM (#41121115)
That's true for any type, not just bool right? And is equivalent of to the observation that any pure function can be replaced by a lookup table.
Re:Where does the name "algebraic data type" come from? by Sharlin on Wednesday July 31, 2024 @08:01PM (#41124837)
Sure, any function T -> U partitions T into |U| subsets. But the case where |U|=2 is special because 2^N is special in being the number of subsets of a set of size N.