Define functions with foldl foldr
<p>I understand the definitions of foldl, foldr, but I have problems with functions defined by them. </p>

<p>For example map with foldr:</p>

<pre><code>map f []       = []
map f l   = foldr (\x xs -&gt; f x : xs) [] l
</code></pre>

<p>I don't understand the <code>(\x xs -&gt; f x : xs)</code>. It is the map function, which foldr takes? But shouldn't it be <code>(\x xs -&gt; f x : f xs)</code>, because <code>map f (x:xs) = f x : map f xs</code>?</p>

<p>Example with foldl:</p>

<pre><code>concat (x:xs) = x ++ concat xs

concat' xs = foldl (++) [] xs
concat'' xs = foldl (\ys y -&gt; ys ++ y) [] xs
</code></pre>

<p>Of course I understand <code>(++)</code>, but what's the logic behind <code>(\ys y -&gt; ys ++ y)</code>? Is it <code>ys = []</code> and <code>y = xs</code>?
So the function takes <code>[]</code> as <code>ys</code> and <code>y</code> is the first element of <code>xs</code> and concates the <code>[]</code> with the <code>y</code>?
Concrete example:</p>

<pre><code>concat'' [1,2,3] = foldl (\ys y -&gt; ys ++ y) [] [1,2,3]
=&gt; foldl (\ys y -&gt; ys ++ y) ((\ys y -&gt; ys ++ y) [] [1]) [2,3]
=&gt; foldl (\ys y -&gt; ys ++ y) [1] [2,3]
=&gt; foldl (\ys y -&gt; ys ++ y) ((\ys y -&gt; ys ++ y) [1] [2]) [3]
=&gt; foldl (\ys y -&gt; ys ++ y) [1,2] [3]
=&gt; foldl (\ys y -&gt; ys ++ y) ((\ys y -&gt; ys ++ y) [1,2] [3]) []
=&gt; foldl (\ys y -&gt; ys ++ y) [1,2,3] []
=&gt; [1,2,3]
</code></pre>

<p>Another thing: <code>concat</code> only takes 1 list <code>xs</code>, so if I want to concat 2 lists?</p>

<pre><code>concat (x:xs) ys = x ++ concat xs ys
concat [1,2,3] [4,5,6] with foldl?
</code></pre>

<p>Reverse:</p>

<pre><code>reverse (x:xs) = reverse xs ++ [x]

reverse'  l = foldl (\xs x -&gt; [x] : xs) [] l
reverse'' l = foldr (\x xs -&gt; xs ++ [x]) [] l
</code></pre>

<p>The foldr is intuitive clear (with the questions from above), but what's behind the reverse order in foldl <code>(\xs x -&gt; [x] : xs)</code>? This <code>foldl (\x xs -&gt; xs ++ [x]) [] l</code> would be wrong, wouldn't it?</p>

<p>Thanks a lot!</p>