[Haskell-beginners] Monoids and Groups
Boris
d12frosted at icloud.com
Thu Mar 26 13:17:37 UTC 2015
Hi,
While they have similarities, they are not the same. Semigroup (S,*) is a set S with associative binary operation *. Monoid is a semigroup that has identity element i such that i * a = a and a * i = a. And group is a monoid in which every element of set has it’s own inverse: a * b = i and b * a = i where b is an inverse of a.
Let’s look at the definition of Monoid in haskell.
class Monoid a where
mempty :: a
-- ^ Identity of 'mappend'
mappend :: a -> a -> a
-- ^ An associative operation
mconcat :: [a] -> a
-- ^ Fold a list using the monoid.
-- For most types, the default definition for 'mconcat' will be
-- used, but the function is included in the class definition so
-- that an optimized version can be provided for specific types.
mconcat = foldr mappend mempty
So we have a set of a, associative binary operation mappend and identity element mempty. The only difference between Monoid a in haskell and monoid in algebra is that Monoid in haskell has mconcat function in it’s definition. But you can ignore it.
I hope it helps.
Cheers, d12frosted
On March 25, 2015 at 16:03:14, Shishir Srivastava (shishir.srivastava at gmail.com) wrote:
Hi,
Reading about Monoids it seems they derive a lot on the algebraic structures of 'Groups' ?
Is it then correct to assume that Monoids can be used to represent 'Groups' ?
If not are there any standard haskell libraries which represent algebraic structures such as 'Groups' , 'Fields' etc.
Thanks,
Shishir Srivastava
_______________________________________________
Beginners mailing list
Beginners at haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150326/ec0ef599/attachment.html>
More information about the Beginners
mailing list