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.

instance Monoid [a] where
        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.magiclo...@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@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


-- 
Rafael Gustavo da Cunha Pereira Pinto
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to