def lmax(l): ans = 0 for i in l: ans = max(ans, i) return ans def nth(l, n): x = 0 for i in l: if x == n: return i else: x = 1 + x def nth(l, n): ans, x = None, 0 for i in l: if x == n: ans = i x = x + 1 return ans def nth(l, n): ans, x = None, 0 for i in l: ans = i if x == n else ans x = x + 1 return ans def nth(l, n): ans, x = None, 0 def step(ans, x, i): newAns = i if x == n else ans newX = x + 1 return newAns, newX for i in l: ans, x = step(ans, x, i) return ans let nth_opt l n = let step (ans, x) i = (if x = n then Some i else ans, x + 1) in List.fold_left step (None, 0), l def unzip(l): lefts, rights = [], [] for i in l: a, b = i lefts = lefts + [a] rights = rights + [a] return lefts, rights let unzip l = let step (lefts, rights) (a, b) = (lefts @ [a], rights @ [b]) in List.fold_left step ([], []) l let unzip l = let step (a, b) (lefts, rights) = (a :: lefts, b :: rights) in List.fold_right step l ([], [])