Warum kannst du die Liste mit foldl umkehren, aber nicht mit foldr in Haskell
Warum kannst du eine Liste mit dem foldl umkehren?
reverse' :: [a] -> [a]
reverse' xs = foldl (\acc x-> x : acc) [] xs
Aber dieser gibt mir einen Kompilierungsfehler.
reverse' :: [a] -> [a]
reverse' xs = foldr (\acc x-> x : acc) [] xs
Erro
Couldn't match expected type `a' with actual type `[a]'
`a' is a rigid type variable bound by
the type signature for reverse' :: [a] -> [a] at foldl.hs:33:13
Relevant bindings include
x :: [a] (bound at foldl.hs:34:27)
acc :: [a] (bound at foldl.hs:34:23)
xs :: [a] (bound at foldl.hs:34:10)
reverse' :: [a] -> [a] (bound at foldl.hs:34:1)
In the first argument of `(:)', namely `x'
In the expression: x : acc