Algebraic Data Types: Things I wish someone had explained about FP
While I really like these blog posts for keeping things light and intuitive, they&#x27;re also sprinkled with claims that go a bit too far.<p><pre><code>    &gt; Arrays, Objects, Maps, WeakMaps, and Sets are all algebraic data types
</code></pre>
This isn&#x27;t really true on a couple levels. Algebraic Data Types are described through a small set of composition (data) or decomposition (codata) operations. Arrays, Maps, and Objects might be explainable in this way (though, really, we&#x27;d just be modeling them with ADTs). WeakMaps and Sets really cross the line though. WeakMaps, by their nature, need to appeal to something much more than just ADTs and Sets require &quot;quotienting&quot; to unify sets which contain the same elements in various ways. You can build the &quot;raw stuff&quot; from ADTs, but you won&#x27;t have something that really behaves much like these types at all until you add in something extra.<p>The emphasis on sum types is huge, but it leaves out something critical: &quot;JavaScript doesn’t have a lot of built-in features for sum types&quot; is true of user-defined sum types (and related to it just not having types all together), but it has great support for a few special sum types: integers, booleans, characters! These sum types are important to talk about because it helps make clear that we already work with sum types all the time! Our basis for distinction and choice is built atop them in any language.<p>Finally, while products and sums get you some wonderful modeling capabilities, the place where Algebraic Data Types really shine is when you add two further capabilities: function types (exponentials) and recursion (fixpoint, which doesn&#x27;t really map to high school algebra). Those are clearly built into JavaScript as well and would be great to discuss as well.