let apply m =
let rec app a =
try
Map.find a m
with
Not_found ->
(match a with
| Var _ -> a
| App(f, al) ->
let al' = mapl app al in
if al == al' then a else App(f, al'))
in
app