[Haskell-cafe] Functor0?

Evan Laforge qdunkan at gmail.com
Mon Jan 16 06:26:32 CET 2012

Often when I define some type that wraps something else, I find myself writing
a function like the following:

newtype Thing = Thing X
liftThing f (Thing x) = Thing (f x)

It's like a Functor, but I can't make it an instance because Functor
requires that the type be parametric.  So I've been using type families to
make a kind of "0 argument functor":

class Functor0 a where
    type Elem a :: *
    fmap0 :: (Elem a -> Elem a) -> a -> a

instance Functor0 Thing where
    type Elem Thing = X
    fmap0 = liftThing

Is there a name for this?  A better way to do it?

More information about the Haskell-Cafe mailing list