title: Turning quadratic-time program into a linear-time one with help of monoid?
body: <p>While I was reading a paper dedicated to Yoneda lemma and it's relationship with profunctors optics, I've encountered following statement:</p>
  
  <blockquote>
    <p>...Cayley’s
    Theorem for monoids (which is the trick that enables the use of an accumulating parameter, which
    can often turn a quadratic-time program into a linear-time one)...</p>
  </blockquote>
  
  <p>The part I am interested in is <code>the trick ... quadratic-time... into a linear-time one</code>. How does it work? </p>
  
  <p>P.S. I am familiar with monoids and common math notation for them, so feel free to use it, if necessary or stick to Haskell.</p>