foldr
is actually easy: Given a list (written with :
and []
) like
a : (b : (c : (d : [])))
then applying foldr h x
to it will replace every :
with `h`
and []
with x
:
a `h` (b `h` (c `h` (d `h` x)))
Compare that with what map f
would to the list:
f a : (f b : (f c : (f d : [])))
This should guide you in choosing h
and x
so that foldr h x = map f
.