[Haskell-cafe] Functor and Haskell

Ross Paterson ross at soi.city.ac.uk
Wed Apr 22 18:40:18 EDT 2009


On Wed, Apr 22, 2009 at 03:14:03PM -0700, Daryoush Mehrtash wrote:
> The Haskell Wikibooks also says the same thing:
> 
>     Functors in Haskell are from Hask to func, where func is the
>     subcategory of Hask defined on just that functor's types. E.g. the
>     list functor goes from Hask to Lst, where Lst is the category
>     containing only list types, that is, [T] for any type T. The
>     morphisms in Lst are functions defined on list types, that is,
>     functions [T] -> [U] for types T, U.

That's true, but not a particularly helpful view.  Any functor F : C -> D
can be viewed as a functor from C to the full subcategory of D on objects
of the form F A for A an object of C.  But then different functors map to
different categories and you can't talk about natural transformations
between them.  Composing functors also becomes impossible.

The simple view is that [], Maybe and Id are all functors from Hask to
Hask.  Then listToMaybe :: [a] -> Maybe a is a natural transformation
from [] to Maybe, because

	fmap f . listToMaybe = listToMaybe . map f


More information about the Haskell-Cafe mailing list