implementing function monoid