let rec map f a =
match a with
| App(Pair(op), al) ->
(match op, al with
| Cons, [b1;b2] ->
let b1' = map f b1
and b2' = map f b2 in
if b1 == b1' && b2 == b2' then a else
mk_cons b1' b2'
| Car, [b] ->
let b' = map f b in
if b == b' then a else mk_car b'
| Cdr, [b] ->
let b' = map f b in
if b == b' then a else mk_cdr b'
| _ ->
f a)
| _ ->
f a