ocaml - List.iter & List.fold_right used together -
i trying use fold_right , list.iter functions in list module. there anyway use them in conjunction 1 another?
let step nfa start transition = let transition_list = get_transition nfa in list.iter ( fun state -> list.fold_right (fun ct nl -> if ((get_pre_trans transition)= state && (get_trans ct) = transition) (get_post_transition transition)::nl else nl ) transition_list [] ) start ;;
** get_xxx functions values tuple there pre-transition, transition value, , post-transition.
return error: error: expression has type 'a list expression expected of type unit.
not sure do.
the body of function pass iter
contains 1 expression, call fold_right
, evaluates value of type list
, iter
signature requires pass function, returns value of type unit
. compiler tries you. if you're not interested in value fold_right
evaluated, can ignore using ignore
function, takes value of type , returns value of type unit
. on other hand, if don't want discard it, shouldn't use iter
, , use fold_right
or, better, fold_left
.
and, finally, answering question, yes, there're ways combine them together, usually, if you're applying fold inside iter, you're doing wrong.