Functional Programming, Abstraction, and Naming Things
stephendiehl.com
stephendiehl.com
The abstract method in mathematics, as it is sometimes called, is what results when one takes a similar attitude to mathematical objects. This attitude can be encapsulated in the following slogan: a mathematical object is what it does. ...
—Tim Gowers, A Very Short Introduction to Mathematics
https://sarabander.github.io/sicp/html/2_002e2.xhtml#g_t2_00...
1. If compiler would know which function is invertible, it could automatically build inverses of composed functions. And for instance, you could pattern match on a function argument, and it would automatically do the inversion for you!
2. Knowing that some operator is a group operator could lead to efficient optimizations. Consider a collection over which you calculate a folded value, where the folding is a group operator. Then knowing that, you could use group element inverse to recalculate the value when the collection changes, instead of recalculating it over the whole collection. Example: You need to keep a sum of list of numbers. Since addition is group operator, removing elements could cause the sum to be recalculated via subtraction of the single element.
https://hackage.haskell.org/package/lens-4.13/docs/Control-L...
Read more Dijkstra!
I think the part that eludes many tutorials and articles, is explaining what exactly we're calling a monoid or a monad. Is it the actual set of laws? Is it an abstract "object"? And although there are many attempts at simplifying their explanations, I found that is necessary to grasp the concept of a category first. Really having an intuition for a category gives way to understanding functors, etc. because that's what their definition is based on. Attempting to explain functors, etc. just with functions (of any language) will leave the learner hanging as to what exactly a functor is, since languages just implement them, but category theory provides the underlying abstraction that gives them context.
If we had an interface called "Appendable", that leaves room for arguing over the boundaries of what "really" counts as "appending". This is contentious, because interfaces define what we should be able to rely on.
In Haskell, it's entirely clear what is and is not a Semigroup. Does it follow the Semigroup laws? Okay, it's a Semigroup! What can I rely on if I ask for a Semigroup? The Semigroup laws.
Discussion of, say, whether "container" is a good way to think of a "functor" is more quickly recognized as a purely pedagogical question - which doesn't mean it can't be contentious, but doesn't as much get in the way of getting work done.
I can see how one can start from types, but I don't see how one can start from abstract algebra (or categories or something). That is, possibly not to have fully specified objects that you work with.
Dependently typed languages are what you use for this kind of thing.
I mean, in untyped lambda calculus you start with simple objects that are fully specified and you compose them to get more complex objects. I think one should be able to do the "opposite" thing, i.e. start with potentially complicated objects and restrict those down by adding relational conditions on them.
So I am looking for some (minimalistic) formalism to do that, something like "lambda calculus in reverse". In classic Lisp, there were operators CAR, CDR and EQ which let you introspect any lambda expression. So maybe there should exist a formalism having these decompositional operators as primitives..
[0] http://wiki.portal.chalmers.se/agda/pmwiki.php?n=Libraries.S...
Roughly the same way one can express the concept in mathematics. You say "this set forms a monoid under that operation, with such-and-such identity element", and optionally include some argument (or, ideally, proof) that this is the case.
In (traditional/most) math, that is only checked by humans.
In Haskell, it is checked by humans and hopefully tests (laws often make great QuickCheck properties!).
Anyway, I've tried to explain such stuff, and my best success rate is by first throwing people out of their comfort zone by asking them to explain what's a number, or something equally fundamental.