The cosmic merger rate of neutron stars and black holes