[Haskell-cafe] Questions about the Functor class and it's use in "Data types à la carte"

Corey O'Connor coreyoconnor at gmail.com
Fri Dec 14 14:44:16 EST 2007

I'm working through the interesting paper "Data type à la carte" and
am confused by the Functor instance for Val. I think this stems from
some confusion of mine regarding the Functor class in general.

The Functor instance I'm confused about is:
    instance Functor Val where
        fmap f (Val x ) = Val x

where Val is defined as:
    data Val e = Val Int

Is this the only valid Functor instance for the Val type? Even though
I'd, naively, expect the Functor instance to look like:
    instance Functor Val where
        fmap f (Val x) = Val (f x)

I suspect that would not work out due to the type of the Val
constructor. Is this correct?

The reason I find all this odd is because I'm not sure how the type
class Functor relates to the category theory concept of a functor. How
does declaring a type constructor to be an instance of the Functor
class relate to a functor? Is the type constructor considered a

Any help would be, of course, greatly appreciated.

-Corey O'Connor

More information about the Haskell-Cafe mailing list