let apply_opt (m, s, d_opt) = function None -> d_opt | Some k -> apply (m, s, d_opt) k