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.
fold
onIO
, which is aFunctor
, but notFoldable
? – Zeta Jul 30 '15 at 13:33fmap
a special case offold
? I can't imagine how you would be able to implement either in terms of the other, which is what I think of when I think of "more fundamental". – Dietrich Epp Jul 30 '15 at 13:47fmap
in my post was a typo. I meanmap
. – akonsu Jul 30 '15 at 14:01