I have foldl:
let rec foldl f lst acc = match lst with
| [] -> acc
| hd::tl -> foldl f lst (f hd acc)
and I have foldr:
let rec foldr f lst acc = match lst with
| [] -> acc
| hd::tl -> f hd (foldr f tl acc);;
I want to declare foldl using foldr.
How could this be done?
Informally, according to your definitions,
and so we need
and thus it must be
i.e., in pseudocode,
Now you can write this in your syntax.
Note that the standard
fold_leftuses the flipped order of accumulation compared to yours (which was also used in the previous version of this answer).