13 Nov 17:33
Re: Could someone teach me why we use Data.Monoid?
Rafael Gustavo da Cunha Pereira Pinto <RafaelGCPP.Linux <at> gmail.com>
2009-11-13 16:33:42 GMT
2009-11-13 16:33:42 GMT
Disclaimer: I don't really know all about category theory, so some definitions might not be absolutely correct.
Monoid is the category of all types that have a empty value and an append operation.
The best example is a list.
mempty = []
mappend = (++)
Why do I need it? Well, you can think of a function where you need to incrementally store data.
Storing them to a Monoid, you can start with a list and then change to a Set, without changing the function itself, because it would be defined based on the Monoid operations.
instance Ord a => Monoid (Set a) where
mempty = empty
mappend = union
mconcat = unions
Hope I have helped!
Regards,
Rafael
On Fri, Nov 13, 2009 at 14:14, Magicloud Magiclouds <magicloud.magiclouds <at> gmail.com> wrote:
Hi,
I have looked the concept of monoid and something related, but
still, I do not know why we use it?
--
竹密岂妨流水过
山高哪阻野云飞
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
--
Rafael Gustavo da Cunha Pereira Pinto
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe <at> haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RSS Feed