foldr and foldl Flashcards

1
Q

Explain the map function

A

loop over list element-by-element, append new element to new list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain the foldl function

A

loop over list element-by-element, update accumulator using current accumulator and element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the foldr function

A

foldr : loop over reverse list element-by-element, update accumulator using current accumulator and element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give the map function definition

A

map :: (a -> b) -> [a] -> [b]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Give the foldl function definition

A

foldl :: (b -> a -> b) -> b -> [a] -> b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Give the foldr function definition

A

foldr :: (a -> b -> b) -> b -> [a] -> b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between foldl and foldr

A

foldl evaluates from left to right (left-associative)

foldr evaluates from right to left (right-associative)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly