Foundations of Logic and Functional Programming