Can somebody explain to me why the following works:


add2 = foldr (\ x xs -> x + 2 : xs) []

 

but this does not:

appendTest = foldr(\ x xs -> x ++ "Test" : xs) []

 

I get a type mismatch between [[[Char]]] and [[Char]] when I call

appendTest ["one", "two"]

 

I need to do it this way:

 

appendTest = foldr(\ x xs -> (\ x -> x++ "Test") : xs) []

 

I am not sure why though, especially since the Int example works. Sure, String is [Char], but I can't see why the first version of appendTest expects a [[[Char]]] instead of a [[Char]].

 

Thanks a lot!