What Monoids teach us about software
Here&#x27;s the ELI5 of monoids used in programming that might help get the idea across:<p>Conceptually, a monoid is anything that:<p>- Has a &quot;zero-value&quot; (mempty, e.g., 0)<p>- Can be &quot;appended&quot; together (mappend, e.g., +)<p>- Has an identity with the zero-value: x + 0 == x, 0 + x == x<p>- Is associative: x + y + z == (x + y) + z == x + (y + z)<p>This isn&#x27;t limited to just arithmetic with operators like +. You can define whole new types as monoids if they have these characteristics. For example, we can merge together configuration files by using monoid operators (in pseudo-code):<p><pre><code>    -- Zero Value
    mempty == {}

    -- Append
    {&quot;color&quot;: &quot;Blue&quot;} `mappend` {&quot;fontSize&quot;: 12} == {&quot;color&quot;: &quot;Blue&quot;, &quot;fontSize&quot;: 12}

    -- Identity
    {&quot;color&quot;: &quot;Blue&quot;} `mappend`               {} == {&quot;color&quot;: &quot;Blue&quot;}
                   {} `mappend` {&quot;fontSize&quot;: 12} == {&quot;fontSize&quot;: 12}

    -- Associativity
    {} `mappend` {&quot;a&quot;: &quot;b&quot;} `mappend` {&quot;c&quot;: &quot;d&quot;}
        == ({} `mappend` {&quot;a&quot;: &quot;b&quot;}) `mappend` {&quot;c&quot;: &quot;d&quot;}
        ==  {} `mappend` ({&quot;a&quot;: &quot;b&quot;} `mappend` {&quot;c&quot;: &quot;d&quot;})
</code></pre>
There&#x27;s no need to break out the really formal definitions if you&#x27;re just trying to get some nice working code.<p>Borrowing from mathematics is beneficial because we can work with structures that have simple but useful guarantees. In Haskell, you can expect all the above to be true for correct type instances of Monoid, without the implementation details at hand. It&#x27;s a core tenet of functional programming to disarm complexity with simplicity.