Not heard of it referred to as the ‘Expression Problem’, but that is a good example as to why both pure functional and OOP are very bad at solving it, protocols are not really better than OOP here, what would work best is multiple polymorphic dispatch (rehashing a bit of the article to set up context here), like CLOS (Lisps’s OOP system) supports, where you can dynamically dispatch on more than one argument, which is easily solved via pattern matching in Elixir (but requires horrible dispatch trees and such for OOP). Here’s an example (typed in post so probably errors somewhere) using my ProtocolEx library (which builds matchers at compile-time, think of it as a significantly more powerful version of the built-in Protocols):

Or whatever, there’s many ways of doing it, and you can split each case of overlap into it’s own module, or put them all together, or define defaults, or control ordering, or let dependencies of this add in their own things for their own types, or use tagged tuples instead of structs, or whatever.

The example in the article I wrote is achieving polymorphic dispatch using protocols, so protocols are much better than OOP for solving this specific problem.

Pattern matching in elixir doesn’t get you everything you need to solve the expression problem. You also need to be able to extend the patterns that you can match on, dynamically. Meaning the patterns you match on need to be extensible. The only way you can achieve this is with protocols AFAIKT