Haskell foldr results in type error while foldl doesn't
问题 I'm working through "Haskell Programming From First Principles". In the chapter on Folding Lists, exercise 5f, when I evaluate foldr const 'a' [1..5] I get No instance for (Num Char) arising from the literal ‘1’ However, with foldl const 'a' [1..5] I get 'a' . I get that the folds are lazy, foldr doesn't traverse the spine and foldl does. But even looking at the definitions of foldr and foldl, foldr f z [] = z foldr f z (x:xs) = f x (foldr f z xs) foldl f z [] = z foldl f z (x:xs) = foldl f