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
foldrto achieve this, you would usefoldr (fn (xs, result) => ...) initial xsswhereinitialis one of the operands to merge (it works as the firstresultwhile the result of merging works as the subsequentresults). 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.