A Constraint-Based Approach to Learning and Reasoning