Considering a type with kind * -> *, I'm trying to find rules and build intuition for when you can and when you cannot have Functor for this type.
So far the rules that I see are the following:
Functor
instance for the container types that have restrictions
on the contained values.Example: You cannot have a Functor
instance for Set
because Ord
is needed for the contained value
Functor
instance for contravariant data types. Example:
newtype Contra a = Contra (a -> Int)
Besides this, are there other situations?
In addition to your rules:
* -> *
Functor
instance for the container types that have restrictions on the contained values.Functor
instance for contravariant data types.I would add a few:
Functor
instance for invariant data types. e.g. data Iso a b = Iso (a -> b) (b -> a)
GADTs often cannot have a Functor
instance. For example,
data Foo a where
Foo :: Foo Int
Perhaps you would somehow want to lump this into the "only covariant" rule somehow (it's not clear to me what variance this even has), or the "unrestricted container types" rule somehow (GADTs introduce type equalities that are very constraint-like).
However, keep in mind that these rules apply to Functor
only, not to functors in general. I expect any stupid type (of appropriate kind) you can cook up will be a functor on some suitable category closely related to Hask.