0
votes

So I have a function like so

let test (item: 'a ) (factors: items) : ('b list) =
  ....

This function takes in an item of some 'a elements and my own items type, which is another list of items I pass to it. I return a list of a different type later after doing some stuff

How do I use List.fold_left with this function so that if I have a list of 'a items, I can just apply test to each one individually, and pass 'factors' to all of them, and then so that I can concatenate the resultant 'b type lists for each one.

For example, the I would need to process the following list:

[somea; someb; somec]
as 
(test somea factors)@(test someb factors)@(test somec factors)

Is this a task that List.fold_left is not applicable for? Is there some other function I can use? I can't recursively traverse and call the function because of some mutually-recursive problems going on with the other methods in my code so is there another way? Would List.map be useful here instead?

1

1 Answers

0
votes

For this particular purpose, things would go better if factors was the first parameter of test. Let's call this function fliptest:

let fliptest a b = test b a

So then your function looks like this (it seems to me):

let process factors list =
    List.concat (List.map (fliptest factors) list)

(If this isn't quite right, it's probably close.)