Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a name for arrows of the type a -> a (in Haskell notation) in category theory?

Whats the name of arrows in category theory that have this type:

a -> a

"From a type(?) to another object of the same type"

Or maybe there's no particular name for them?

In other words: Is there a name for the set of all arrows that go from any type a to the same type a? Examples of arrows (functions?) of that set:

\x->x+x   :: Int->Int
\x-> "hello, " ++ x :: String -> String
...

Edit

@leftaroundabout says that I'm using OO definition of object for category theory, which is wrong. Therefore, what I'm really asking is: "In category theory, in a category đť“’ what is the name for a morphism from some object O of đť“’ to O itself?"

like image 921
Lay González Avatar asked Mar 06 '14 21:03

Lay González


2 Answers

If I'm correct in interpreting your question as "what do we call morphisms from an object to itself in category theory?", then the word you're looking for is endomorphism.

like image 108
gspr Avatar answered Sep 22 '22 15:09

gspr


The word you're looking for, as many others have said, is "endomorphism." But in a more concrete note it's worth mentioning here the Endo type in Data.Monoid:

data Endo a = Endo { appEndo :: a -> a }

instance Monoid (Endo a) where
    mempty = Endo id
    Endo f `mappend` Endo g = Endo (f . g)

This type is sometimes useful. For example, as Brent Yorgey explains, folds are made of monoids:

import Data.Monoid

foldr :: (a -> b -> b) -> b -> [a] -> b
foldr f z xs = appEndo (mconcat (map (Endo . f) xs)) z

foldl :: (b -> a -> b) -> b -> [a] -> b
foldl f z xs = appEndo (mconcat (map (Endo . flip f) (reverse xs))) z

So, since monoids are associative, oftentimes folds can be parallelized (with a divide-and-conquer strategy) by first rewriting them in terms of Endo, and then replacing the specific Endo b for that fold with some more concrete type that allows for some of the work to be done at each mappend step.

like image 31
Luis Casillas Avatar answered Sep 19 '22 15:09

Luis Casillas