[Haskell-cafe] Categories (cont.)
Gershom Bazerman
gershomb at gmail.com
Fri Dec 21 04:36:15 CET 2012
On 12/20/12 10:05 PM, Jay Sulzberger wrote:
> What does the code for going backwards looks like? That is,
> suppose we have an instance of Category with only one object.
> What is the Haskell code for the function which takes the
> category instance and produces a monoid thing, like your integers
> with 1 and usual integer multiplication? Could we use a
> "constraint" at the level of types, or at some other level, to
> write the code? Here by "constraint" I mean something like a
> declaration that is a piece of Haskell source code, and not
> something the human author of the code uses to write the code.
instance C.Category k => Monoid (k a a) where
mempty = C.id
mappend = (C..)
The above gives witness to the fact that, if I'm using the language
correctly, if we choose any object (our "a") in any given category, this
induces a monoid with the identity morphism as unit and composition of
endomorphisms as append.
The standard libraries in fact provide this instance for the function
arrow category (under a newtype wrapper):
newtype Endo a = Endo { appEndo :: a -> a }
instance Monoid (Endo a) where
mempty = Endo id
Endo f `mappend` Endo g = Endo (f . g)
--Gershom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121220/5e54ecd1/attachment.htm>
More information about the Haskell-Cafe
mailing list