Constraint Handling Rules

  • Authors:
  • Tom Schrijvers

  • Affiliations:
  • Department of Computer Science, K.U.Leuven, Belgium

  • Venue:
  • ICLP '08 Proceedings of the 24th International Conference on Logic Programming
  • Year:
  • 2008

Quantified Score

Hi-index 0.00

Visualization

Abstract

Constraint Handling Rules (CHR) [2,5] is a high-level programming language based on multi-headed, committed-choice, guarded multiset rewrite rules. Originally designed in 1991 by Frühwirth for the particular purpose of adding user-defined constraint solvers to a host-language, CHR has matured over the last decade to a powerful and elegant general-purpose language with a wide spectrum of application domains. Different semantics have been proposed for the language, based on various logics (first-order logic, linear logic, ...). These logics, in combination with rewriting techniques, have been used to study program properties such as soundness and completeness, confluence, termination, ...While that line of work treats CHR as a calculus, this tutorial teaches CHR as a proper programming language. As a programming language, CHR seems simple enough: The programmer specifies a number of rewrite rules, and the CHR engine applies these rules exhaustively to an initial (multi-)set of constraints. Yet, this simplicity hides great power: e.g., the power to quickly prototype new constraint solvers, the power to implement Prolog's co-routining predicates freeze/2 and when/2 in a single CHR rule each, and the power to subsume Guarded Horn Clauses while still not exploiting CHR's full potential. Moreover, CHR is the only declarative language known in which every algorithm can be implemented with optimal space and time complexity [4]. Unfortunately, few Prolog programmers are aware of the CHR language or that it is available in their Prolog system. These programmers are unable to tap into CHR's power, so they have to go to great length to accomplish even simple tasks. Or they simply give up. This tutorial shows how to use CHR for solving their problems quickly and elegantly. Simple examples teach interactively how to write and reason about CHR programs, and what problems one can solve effectively with CHR. This tutorial starts with ground CHR, the three types of rules, and the refined semantics [1] which is based on the notion of the active constraint and its occurrences. Other topics covered are triggering of rules, the propagation history, the use of data structures and the host language, declarations and impure features, and the common pitfalls of CHR. This tutorial intends to make the attendants aware of CHR's strengths as a programming language, and teaches them when and how to apply CHR for small to medium sized problems. The full set of tutorial slides is available at http://www.cs.kuleuven.be/~dtai/projects/CHR/ . About the Speaker. Tom Schrijvers is a post-doctoral researcher at the K.U.Leuven in Belgium, who has defended his Ph.D. thesis on Analyses, Optimizations and Extensions of Constraint Handling Rules in 2005 [3]. His CHR implementation, the K.U.Leuven CHR system, is the most advanced in its kind and is in wide-spread use in many Prolog systems. Tom uses CHR on a daily basis, for implementing his compiler, for supporting his type checking and test generation research, or simply for gaining an edge in the Prolog Programming Contest.