OCaml: retain value of variable with control statements -
i'm new ocaml / functional programming, , i'm confused implementation of things relatively simple other languages know. use , help. chiefly: in program i'm working on, either increment or decrement variable based on parameter. here's representative of have: let tot = ref 0 in = 0 s if test_num > 0 tot := !tot + other_num else tot := !tot - other_num done;; this not way go it, because if else statement never taken, code acts if is, each , every time, presumably because it's closer bottom of program? know ocaml has pretty sophisticated pattern matching, within level of coed need access handful of lists i've created, and, far understand, can't access lists top-level function without passing them parameters. i know i'm going wrong way, have no idea how idiomatically. suggestions? thanks. edit here's more concise example: let ex_list = [1; -2; 3; -4] in let max_mem = ref 0 in let mem = ref 0 in let () = ...