Skip to main content

CHR for Imperative Host Languages

  • Chapter
Book cover Constraint Handling Rules

Part of the book series: Lecture Notes in Computer Science ((LNAI,volume 5388))

Abstract

In this paper, we address the different conceptual and technical difficulties encountered when embedding CHR into an imperative host language. We argue that a tight, natural integration leads to a powerful programming language extension, intuitive to both CHR and imperative programmers. We show how to compile CHR to highly optimized imperative code. To this end, we first review the well-established CHR compilation scheme, and survey the large body of possible optimizations. We then show that this scheme, when used for compilation to imperative target languages, leads to stack overflows. We therefore introduce new optimizations that considerably improve the performance of recursive CHR programs. Rules written using tail calls are even guaranteed to run in constant space. We implemented systems for both Java and C, following the language design principles and compilation scheme presented in this paper, and show that our implementations outperform other state-of-the-art CHR compilers by several orders of magnitude.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. The Constraint Handling Rules (CHR) programming language homepage, http://www.cs.kuleuven.be/~dtai/projects/CHR/

  2. Frühwirth, T.: Theory and practice of Constraint Handling Rules. J. Logic Programming, Special Issue on Constraint Logic Programming 37(1–3), 95–138 (1998)

    MathSciNet  MATH  Google Scholar 

  3. Sneyers, J., Van Weert, P., Schrijvers, T., De Koninck, L.: As time goes by: Constraint Handling Rules — a survey of CHR research between 1998 and 2007. Journal of Theory and Practice of Logic Programming (submitted, 2008)

    Google Scholar 

  4. Holzbaur, C., Frühwirth, T.: A Prolog Constraint Handling Rules compiler and runtime system. In: [76], pp. 369–388

    Google Scholar 

  5. Schrijvers, T.: Analyses, optimizations and extensions of Constraint Handling Rules. Ph.D thesis, K.U.Leuven, Belgium (June 2005)

    Google Scholar 

  6. Schrijvers, T., Demoen, B.: The K.U.Leuven CHR system: Implementation and application. In: [77], pp. 8–12

    Google Scholar 

  7. Duck, G.J.: Compilation of Constraint Handling Rules. Ph.D thesis, University of Melbourne, Australia (December 2005)

    Google Scholar 

  8. Holzbaur, C., García de la Banda, M., Stuckey, P.J., Duck, G.J.: Optimizing compilation of Constraint Handling Rules in HAL. In: [78], pp. 503–531

    Google Scholar 

  9. Abdennadher, S., Krämer, E., Saft, M., Schmauß, M.: JACK: A Java Constraint Kit. In: Hanus, M. (ed.) WFLP 2001: Proc. 10th Intl. Workshop on Functional and (Constraint) Logic Programming, Kiel, Germany. ENTCS, vol. 64, pp. 1–17. Elsevier, Amsterdam (2002), http://pms.ifi.lmu.de/software/jack/

    Google Scholar 

  10. Vitorino, J., Aurelio, M.: Chord (2005), http://chord.sourceforge.net/

  11. Wolf, A.: Adaptive constraint handling with CHR in Java. In: Walsh, T. (ed.) CP 2001. LNCS, vol. 2239, pp. 256–270. Springer, Heidelberg (2001)

    Chapter  Google Scholar 

  12. Van Weert, P.: The K.U.Leuven JCHR system (2008), http://www.cs.kuleuven.be/~petervw/JCHR/

  13. Wuille, P.: CCHR: The fastest CHR implementation, in C (2008), http://www.cs.kuleuven.be/~pieterw/CCHR/

  14. Frühwirth, T.: Constraint Handling Rules. Cambridge University Press, Cambridge (to appear, 2008)

    MATH  Google Scholar 

  15. Duck, G.J., Stuckey, P.J., García de la Banda, M., Holzbaur, C.: The refined operational semantics of Constraint Handling Rules. In: Demoen, B., Lifschitz, V. (eds.) ICLP 2004. LNCS, vol. 3132, pp. 90–104. Springer, Heidelberg (2004)

    Chapter  Google Scholar 

  16. Duck, G.J., Stuckey, P.J., García de la Banda, M., Holzbaur, C.: Extending arbitrary solvers with Constraint Handling Rules. In: PPDP 2003, Uppsala, Sweden, pp. 79–90. ACM Press, New York (2003)

    Google Scholar 

  17. Abdennadher, S.: Rule-based Constraint Programming: Theory and Practice. Habilitationsschrift, Institute of Computer Science, LMU, Munich, Germany (July 2001)

    Google Scholar 

  18. Abdennadher, S., Schütz, H.: CHR ∨ , a flexible query language. In: Andreasen, T., Christiansen, H., Larsen, H. (eds.) FQAS 1998. LNCS, vol. 1495, pp. 1–14. Springer, Heidelberg (1998)

    Chapter  Google Scholar 

  19. Krämer, E.: A generic search engine for a Java Constraint Kit. Diplomarbeit, Institute of Computer Science, LMU, Munich, Germany (January 2001)

    Google Scholar 

  20. Wolf, A.: Intelligent search strategies based on adaptive Constraint Handling Rules. In: [78], pp. 567–594 (2005)

    Google Scholar 

  21. da Figueira Filho, C.S., Ramalho, G.L.: JEOPS - the java embedded object production system. In: Monard, M.C., Sichman, J.S. (eds.) SBIA 2000 and IBERAMIA 2000. LNCS, vol. 1952, p. 53. Springer, Heidelberg (2000)

    Google Scholar 

  22. Pachet, F.: On the embeddability of production rules in object-oriented languages. Journal of Object-Oriented Programming 8(4), 19–24 (1995)

    Google Scholar 

  23. Pachet, F. (ed.): EOOPS 1994: Proc. OOPSLA 1994 Workshop on Embedded Object-Oriented Production Systems, Portland, Oregon, USA (October 2004)

    Google Scholar 

  24. Bouaud, J., Voyer, R.: Behavioral match: Embedding production systems and objects. In: [23]

    Google Scholar 

  25. Van Weert, P., Schrijvers, T., Demoen, B.: K.U.Leuven JCHR: a user-friendly, flexible and efficient CHR system for Java. In: [79], pp. 47–62

    Google Scholar 

  26. Wuille, P., Schrijvers, T., Demoen, B.: CCHR: the fastest CHR implementation, in C. In: [80], pp. 123–137

    Google Scholar 

  27. Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Reading (1995)

    MATH  Google Scholar 

  28. Schrijvers, T., Demoen, B., Duck, G.J., Stuckey, P.J., Frühwirth, T.: Automatic implication checking for CHR constraints. In: RULE 2005: 6th Intl. Workshop on Rule-Based Programming, Nara, Japan, January 2006. ENTCS, vol. 147(1), pp. 93–111. Elsevier, Amsterdam (2006)

    Google Scholar 

  29. Fages, F., de Oliveira Rodrigues, C.M., Martinez, T.: Modular chr with ask and tell. In: [81], pp. 95–110

    Google Scholar 

  30. Kernighan, B.W., Ritchie, D., Ritchie, D.M.: C Programming Language, 2nd edn. Prentice Hall PTR, Englewood Cliffs (1988)

    MATH  Google Scholar 

  31. Van Weert, P.: K.U.Leuven JCHR User’s Manual (2008). In: [12]

    Google Scholar 

  32. Gosling, J., Joy, B., Steele, G., Bracha, G.: The Java Language Specification, 3rd edn. The Java Series. Prentice Hall, Englewood Cliffs (2005)

    MATH  Google Scholar 

  33. Bracha, G.: Generics in the Java Programming Language (July 2004) (Tutorial)

    Google Scholar 

  34. Sun Microsystems, Inc.: The Collections framework: API’s and developer guides (2008), http://java.sun.com/javase/6/docs/technotes/guides/collections/

  35. Sun Microsystems, Inc.: JavaBeans (2008), http://java.sun.com/products/javabeans/

  36. Van Weert, P.: Compiling Constraint Handling Rules to Java: A reconstruction. Technical Report CW 521, K.U.Leuven, Dept. Comp. Sc. (August 2008)

    Google Scholar 

  37. Sneyers, J., Schrijvers, T., Demoen, B.: The computational power and complexity of Constraint Handling Rules. In: [79], pp. 3–17

    Google Scholar 

  38. De Koninck, L., Sneyers, J.: Join ordering for Constraint Handling Rules. In: [80], pp. 107–121

    Google Scholar 

  39. Duck, G.J., Schrijvers, T.: Accurate functional dependency analysis for Constraint Handling Rules. In: [79], pp. 109–124

    Google Scholar 

  40. Schrijvers, T., Stuckey, P.J., Duck, G.J.: Abstract interpretation for Constraint Handling Rules. In: Barahona, P., Felty, A. (eds.) PPDP 2005, Lisbon, Portugal, July 2005, pp. 218–229. ACM Press, New York (2005)

    Google Scholar 

  41. Sneyers, J., Schrijvers, T., Demoen, B.: Guard reasoning in the refined operational semantics of CHR. In: Schrijvers, T., Frühwirth, T. (eds.) Constraint Handling Rules. LNCS(LNAI), vol. 5388, pp. 213–244. Springer, Heidelberg (2008)

    Chapter  Google Scholar 

  42. Sneyers, J., Schrijvers, T., Demoen, B.: Memory reuse for CHR. In: Etalle, S., Truszczyński, M. (eds.) ICLP 2006. LNCS, vol. 4079, pp. 72–86. Springer, Heidelberg (2006)

    Chapter  Google Scholar 

  43. Van Weert, P.: Optimization of CHR propagation rules. In: ICLP 2008: Proc. 24rd Intl. Conf. Logic Programming, Udine, Italy, December 2008. LNCS. Springer, Heidelberg (accepted, 2008)

    Google Scholar 

  44. Sneyers, J., Schrijvers, T., Demoen, B.: Dijkstra’s algorithm with Fibonacci heaps: An executable description in CHR. In: [82], pp. 182–191

    Google Scholar 

  45. Holzbaur, C., Frühwirth, T.: Compiling Constraint Handling Rules into Prolog with attributed variables. In: Nadathur, G. (ed.) PPDP 1999. LNCS, vol. 1702, pp. 117–133. Springer, Heidelberg (1999)

    Chapter  Google Scholar 

  46. Rossi, F., van Beek, P., Walsh, T. (eds.): Handbook of Constraint Programming. Foundations of Artificial Intelligence. Elsevier, Amsterdam (2006)

    MATH  Google Scholar 

  47. Holzbaur, C.: Metastructures versus attributed variables in the context of extensible unification. In: Proc. 4th Intl. Symposium on Programming Language Implementation and Logic Programming, pp. 260–268. Springer, Heidelberg (1992)

    Chapter  Google Scholar 

  48. Schulte, C., Stuckey, P.J.: Efficient constraint propagation engines. Under consideration for ACM Transactions on Programming Languages and Systems (2008)

    Google Scholar 

  49. Schrijvers, T., Demoen, B.: Antimonotony-based delay avoidance for CHR. Technical Report CW 385, K.U.Leuven, Dept. Comp. Sc (July 2004)

    Google Scholar 

  50. Van Weert, P.: A tale of histories. In: [81], pp. 79–94

    Google Scholar 

  51. Probst, M.: Proper tail recursion in C. Diplomarbeit, Institute of Computer Languages, Vienna University of Technology (2001)

    Google Scholar 

  52. Free Software Foundation: GCC, the GNU Compiler Collection (2008), http://gcc.gnu.org/

  53. Bauer, A.: Compilation of functional programming languages using GCC—Tail calls. Master’s thesis, Institut für Informatik, Technische Univ. München (2003)

    Google Scholar 

  54. Lindholm, T., Yellin, F.: The Java\(^\textsc{TM}\) Virtual Machine Specification, 2nd edn. Prentice Hall, Englewood Cliffs (1999)

    Google Scholar 

  55. Sun Microsystems, Inc.: Java SE HotSpot at a glance (2008), http://java.sun.com/javase/technologies/hotspot/

  56. Clements, J., Felleisen, M.: A tail-recursive machine with stack inspection. ACM Trans. on Prog. Languages and Systems (TOPLAS) 26(6), 1029–1052 (2004)

    Article  Google Scholar 

  57. Baker, H.G.: CONS should not CONS its arguments, part II: Cheney on the M.T.A. SIGPLAN Notices 30(9), 17–20 (1995)

    Article  Google Scholar 

  58. Ganz, S.E., Friedman, D.P., Wand, M.: Trampolined style. In: Intl. Conf. on Functional Programming, pp. 18–27 (1999)

    Google Scholar 

  59. Wielemaker, J.: An overview of the swi-prolog programming environment. In: Proc. 13th Intl. Workshop on Logic Programming Environments, Mumbai, India (2003), http://www.swi-prolog.org/

  60. Santos Costa, V., et al.: YAP Prolog, http://www.ncc.up.pt/yap/

  61. Chin, W.N., Sulzmann, M., Wang, M.: A type-safe embedding of Constraint Handling Rules into Haskell. Honors thesis, School of Computing, National University of Singapore (2003)

    Google Scholar 

  62. Stuckey, P.J., Sulzmann, M., Wazny, J.: The Chameleon system. In: [77], pp. 13–32

    Google Scholar 

  63. Stuckey, P.J., Sulzmann, M.: A theory of overloading. ACM TOPLAS 27(6), 1216–1269 (2005)

    Article  MATH  Google Scholar 

  64. Duck, G.J.: HaskellCHR (2004), http://www.cs.mu.oz.au/~gjd/haskellchr/

  65. Lam, E.S., Sulzmann, M.: A concurrent Constraint Handling Rules semantics and its implementation with software transactional memory. In: DAMP 2007: Proc. ACM SIGPLAN Workshop on Declarative Aspects of Multicore Programming, Nice, France. ACM Press, New York (2007)

    Google Scholar 

  66. Stahl, M.: STMCHR. In: CHR Homepage [1] (2007)

    Google Scholar 

  67. Schmauß, M.: An implementation of CHR in Java. Diplomarbeit, Institute of Computer Science, LMU, Munich, Germany (November 1999)

    Google Scholar 

  68. Abdennadher, S., Saft, M.: A visualization tool for Constraint Handling Rules. In: Kusalik, A. (ed.) WLPE 2001, Paphos, Cyprus (December 2001)

    Google Scholar 

  69. Robin, J., Vitorino, J.: ORCAS: Towards a CHR-based model-driven framework of reusable reasoning components. In: [82], pp. 192–199

    Google Scholar 

  70. Menezes, L., Vitorino, J., Aurelio, M.: A high performance CHR\({}^\lor\) execution engine. In: [79], pp. 35–45

    Google Scholar 

  71. Wolf, A., Gruenhagen, T., Geske, U.: On incremental adaptation of CHR derivations. In: [76], pp. 389–416

    Google Scholar 

  72. Forgy, C.: Rete: A fast algorithm for the many pattern/many object pattern match problem. Artificial Intelligence 19, 17–37 (1982)

    Article  Google Scholar 

  73. Miranker, D.P., Brant, D.A., Lofaso, B., Gadbois, D.: On the performance of lazy matching in production systems. In: Proc. 8th Intl. Conf. on Artificial Intelligence, pp. 685–692 (1990)

    Google Scholar 

  74. Friedman-Hill, E., et al.: Jess, the rule engine for the Java platform (2008), http://www.jessrules.com/

  75. JBoss: Drools (2008), http://labs.jboss.com/drools/

  76. Holzbaur, C., Frühwirth, T. (eds.): Special Issue on Constraint Handling Rules. Journal of Applied Artificial Intelligence 14(4) (2000)

    Google Scholar 

  77. Frühwirth, T., Meister, M. (eds.): CHR 2004: 1st Workshop on Constraint Handling Rules: Selected Contributions, Ulm, Germany (May 2004)

    Google Scholar 

  78. Abdennadher, S., Frühwirth, T., Holzbaur, C.: Special Issue on Constraint Handling Rules. Theory and Practice of Logic Programming, vol. 5(4–5). Cambridge University Press, Cambridge (2005)

    Google Scholar 

  79. Schrijvers, T., Frühwirth, T. (eds.): CHR 2005: Proc. 2nd Workshop on Constraint Handling Rules. CHR 2005. K.U.Leuven, Dept. Comp. Sc., Technical report CW 421, Sitges, Spain (2005)

    Google Scholar 

  80. Djelloul, K., Duck, G.J., Sulzmann, M. (eds.): CHR 2007: Proc. 4th Workshop on Constraint Handling Rules. CHR 2007, Porto, Portugal (September 2007)

    Google Scholar 

  81. Schrijvers, T., Raiser, F., Frühwirth, T. (eds.): CHR 2008: Proc. 5th Workshop on Constraint Handling Rules. CHR 2008. RISC Report Series 08-10, University of Linz, Austria, Hagenberg, Austria (July 2008)

    Google Scholar 

  82. Fink, M., Tompits, H., Woltran, S. (eds.): WLP 2006: Proc. 20th Workshop on Logic Programming. T.U.Wien, Austria, INFSYS Research report 1843-06-02, Vienna, Austria (February 2006)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2008 Springer-Verlag Berlin Heidelberg

About this chapter

Cite this chapter

Van Weert, P., Wuille, P., Schrijvers, T., Demoen, B. (2008). CHR for Imperative Host Languages. In: Schrijvers, T., Frühwirth, T. (eds) Constraint Handling Rules. Lecture Notes in Computer Science(), vol 5388. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-92243-8_7

Download citation

  • DOI: https://doi.org/10.1007/978-3-540-92243-8_7

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-92242-1

  • Online ISBN: 978-3-540-92243-8

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics