So, I have a little tricky assignment to solve and I am entirely new to functional programming. There is a list of boolean variables (neither strings nor chars cuz the algorithm only takes boolean variables so they were converted)
vars = [p;q;r] and there are 2 algorithms say A and B and one boolean equation eq1 = p & q The loop should perform something like this:
Step1 :let x = A ((B vars[0]) eq1) (The algorithm B works on vars[0] and then algorithm A works together on this and eq1) Step2 : let x1 = A ((B vars[1]) x) (In the next step, eq1 should be replaced with the answer from the previous step and algo B should work on vars[1] Step3: let x2 = A ((B vars[2]) x1)
In other languages, this can be written as a loop with the logic
foreach (i in vars){
x = (A (B vars[i]) eq1)
eq1 = x }
Not sure how such a loop can be written in f#
Since the algorithm doesn't look like it needs an exit condition for the loop, I believe you can simply translate it using mutable variables for
xandeq1, updated in a plainforloop.notes:
i in varsandvars[i]means in your own code sample, it would clarify if you could show a complete working sample and the language it is written in.