As dfeuer says, Set
is a good example of Foldable
, which is not Functor
.
Consider the type of Set.map
:
map :: Ord b => (a -> b) -> Set a -> Set b
Note that this is almost fmap
, but this requires the additional restriction of Ord b
. Since you have this limitation, you cannot make it an instance of Functor
.
Note that Set
not a Haskell functor, even with this restriction. Given the smart settings for Eq
instances, we may break the law that fmap f . fmap g === fmap (f . g)
fmap f . fmap g === fmap (f . g)
. See this question for a broader discussion:
Sets, Functors, and Confusion Eq
As noted there, Set
is a (endo) functor in the β Hask
subcategoryβ with ordered types as sets and order-preserving mappings as morphisms.
Thus, even if this is not obvious, the fact that we cannot make Set
functor actually hints at a genuine mathematical problem, and not just about the limitation of our machinery.
source share