updated unify function to take a list of pairs of types