Use Number as Monoid

I need to use a number (Rational) as the type of journal Writer Monad. Unfortunately, the number is not a Monoid. Is there a module (or something) that creates Numbers instances as Monoid, or should I do it myself?

(I just want to know if it already exists somewhere, so as not to reinvent the wheel, I do not need help if necessary)

+3
source share
1 answer

There are various possible ways to view numbers as a monoid (add or products), so you need to use a wrapper to select it. See the docs for Data.Monoid - either Sumor Product. Obviously, if you need another operation, you must write your own.

+9
source

Source: https://habr.com/ru/post/1760703/


All Articles