[Haskell-cafe] Functor and Haskell

Dan Doel dan.doel at gmail.com
Thu Apr 23 15:34:58 EDT 2009

On Thursday 23 April 2009 2:44:48 pm Daryoush Mehrtash wrote:
> Thanks for this example I get the point now. (at least i think i do :) )
> One more question.... This all being on the same category then the functor
> transformation can also be view as a simple morphism too.  In this example
> the listToMaybe can be viewed as morphism between list and Maybe types that
> are both in the Hask categroy too. right?     If so then what would viewing
> the morphism as natural transformation by you?

listToMaybe in general wouldn't be a morphism in the category, because 
morphisms would be from concrete types to other concrete types. [1] So, if 
you'll excuse some notation I just made up (with a little help from GHC core 
notation :)):

  listToMaybe at Int    :: [Int]    -> Maybe Int
  listToMaybe at Char   :: [Char]   -> Maybe Char
  listToMaybe at String :: [String] -> Maybe String

are all morphisms in the alleged Hask category. Each polymorphic function 
(similar to the above one, at least) defines a family of morphisms like that. 
*But*, that's what a natural transformation is: a family of morphisms, one for 
each object in the category, that commute with functor application in a 
certain way. Thus, one can look at the fully polymorphic listToMaybe as a 
natural transformation:

  listToMaybe :: [] -> Maybe

-- Dan

[1] Maybe you could make up a category where polymorphic types are objects as 
well, but that doesn't seem to be the way people typically go about applying 
category theory to Haskell.

More information about the Haskell-Cafe mailing list