So this is the context. Assuming that I have a function that takes a tuple of 2 experiments and test it against a list of rules. The function should stop whenever the tuple of experiments are correctly verified by a certain rule.
type exp = A | B | Mix of exp * exp | Var of string
type sufficency = exp * exp
type rule = Rule of sufficency * (sufficency list)
let rec findout rules (exp1, exp2) = // return a boolean value
match rules with
| [] -> true
| thisRule::remaining ->
match thisRule with
| (suff, condition) ->
match suff with
| (fstExp, sndExp) ->
let map1 = unify Map.empty exp1 fstExp // I don't mention this function in here, but it is defined in my code
let map2 = unify Map.empty exp2 sndExp
true
findout remaining (exp1, exp2)
The problem is, I have no idea how this could be done with functional programming like this. With imperative programming, it would be easier to loop through the list of rules, rather using recursion to go over the list.
So what should the function return at each stage of the recursion?
I got the warning with that code above
warning FS0020: This expression should have type 'unit', but has type 'bool'. Use 'ignore' to discard the result of the expression, or 'let' to bind the result to a name.
unifyis missing. Also,functional <> recursive. Feel free to useList.tryFindand friends. - John Palmer| ((fstExp, sndExp), condition) :: remaining ->. Also it looks like your case for the empty list should returnfalse, otherwisefindoutwill always return true. - Lee