[Haskell-cafe] Could someone teach me why we use Data.Monoid?
Magicloud Magiclouds
magicloud.magiclouds at gmail.com
Fri Nov 13 12:48:17 EST 2009
Thank you guys. I think I learned a lot. Pretty confusing and interesting.
2009/11/14 Eugene Kirpichov <ekirpichov at gmail.com>:
> For every monoid (M, *, u), the dual to it is the monoid (Dual M, \x y
> -> y * x, u)
> For every type A, there exists the A-endomorphism monoid (A->A, (.),
> id). Endo A is just a newtype for A -> A.
>
> More simply, dualization is flipping the binary operation, and the
> endo monoid is the monoid of functions a->a with composition.
>
> 2009/11/13 Magicloud Magiclouds <magicloud.magiclouds at gmail.com>:
>> I see. Then what is about Dual and Endo? Especially Endo, I completely
>> confused....
>>
>> 2009/11/14 Eugene Kirpichov <ekirpichov at gmail.com>:
>>> There is an astonishing number of things in programming that are monoids:
>>> - Numbers, addition, 0
>>> - Numbers, multiplication, 1
>>> - Lists, concatenation, [] (including strings)
>>> - Sorted lists, merge with respect to a linear order, []
>>> - Sets, union, {}
>>> - Maps, left-biased or right-biased union, {}
>>> - Maps K->V, union where Vs for same K get merged in some other monoid, {}
>>> - For any M: Subsets of M, intersection, M
>>> - Any lattice with an upper bound, minimum, upper bound;
>>> symmetrically for a lower-bounded set
>>> - If (S, *, u) is a monoid, then (A -> S, \f g x -> f x * g x, \x ->
>>> u) is a monoid
>>> - Product (a,b) and co-product (Either) of monoids
>>> - Parsers, alternation, a parser that always fails
>>> - etc.
>>>
>>> The benefits of calling something a monoid arise from using
>>> general-purpose structures operating on monoids:
>>> - Finger trees http://apfelmus.nfshost.com/monoid-fingertree.html
>>> - Aforementioned maps which merge values for a key in a given monoid
>>> - Aforementioned monoids lifted to functions
>>> - Monoidal folds (Data.Foldable)
>>> - ...
>>>
>>> 2009/11/13 Magicloud Magiclouds <magicloud.magiclouds at gmail.com>:
>>>> 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
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Eugene Kirpichov
>>> Web IR developer, market.yandex.ru
>>>
>>
>>
>>
>> --
>> 竹密岂妨流水过
>> 山高哪阻野云飞
>>
>
>
>
> --
> Eugene Kirpichov
> Web IR developer, market.yandex.ru
>
--
竹密岂妨流水过
山高哪阻野云飞
More information about the Haskell-Cafe
mailing list