Because a Functor
is a very general kind of object; not all Functor
s support folds. For example, there is an instance1
instance Functor (a ->) where
-- > fmap :: (b -> c) -> (a -> b) -> (a -> c)
fmap f g = g . f
But, while (a ->)
is a Functor
for all a
, for infinite a
there isn't a reasonable fold
definition. (Incidentally, a 'fold' in general is a catamorphism, which means it has a different type for each functor. The Foldable
type class defines it for sequence-like types.).
Consider what the foldr
definition for Integer -> Integer
would look like; what would the outermost application be? What would the value of
foldr (\ _ n -> 1 + n) 0 (\ n -> n + 1)
be? There isn't a reasonable definition of fold
without a lot more structure on the argument type.
1 (a ->)
isn't legal Haskell for some reason. But I'm going to use it anyway as a more readable version of (->) a
, since I think it's easier for a novice to understand.