If I have a set of lists such as [[1,2,4], [3], [0,9,8]...], and assuming routine 'merge' is predefined, how do I merge these lists into one single list using the foldr function?
The syntax for foldr is : foldr f init [...]; I'm confused what the initial condition should be in this case.
Any help would be appreciated, Thanks.
Using
foldr
to achieve this, you would usefoldr (fn (xs, result) => ...) initial xss
whereinitial
is one of the operands to merge (it works as the firstresult
while the result of merging works as the subsequentresult
s). That is, its type is a list, and it should have the property that merging it with the first of the sub-lists should result in only the first of the sub-lists. There is only one list that does this.