[NumericPrelude] GCD as monoid
Henning Thielemann
lemming at henning-thielemann.de
Sun Jul 4 16:36:49 EDT 2010
On Sun, 4 Jul 2010, Paul McJones wrote:
> Henning,
>
> I don't quite see where you're headed with this proposal. If the problem
> of units is complicating things, would it be useful to define a
> semigroup rather than a monoid?
I encountered that problem when writing some pointer arithmetic in a
Writer monad/applicative functor. I used the Writer monad to maintain the
required alignment, which is the GCD of the alignments of all atomic
pointer accesses. A Writer monad uses the Monoid class for "writing to
something", where in my case "writing" means updating the global
alignment. In practice pointer alignments are always powers of two, but
using GCD we could handle any strange alignment. Then I wanted to define a
GCD Monoid generally, and encountered that Prelude's GCD does not work,
since:
Prelude> gcd 0 (-1)
1
More information about the Numeric-Prelude
mailing list