skip to main content
10.1145/2103656.2103675acmconferencesArticle/Chapter ViewAbstractPublication PagespoplConference Proceedingsconference-collections
research-article

Constraints as control

Published: 25 January 2012 Publication History

Abstract

We present an extension of Scala that supports constraint programming over bounded and unbounded domains. The resulting language, Kaplan, provides the benefits of constraint programming while preserving the existing features of Scala. Kaplan integrates constraint and imperative programming by using constraints as an advanced control structure; the developers use the monadic 'for' construct to iterate over the solutions of constraints or branch on the existence of a solution. The constructs we introduce have simple semantics that can be understood as explicit enumeration of values, but are implemented more efficiently using symbolic reasoning. Kaplan programs can manipulate constraints at run-time, with the combined benefits of type-safe syntax trees and first-class functions. The language of constraints is a functional subset of Scala, supporting arbitrary recursive function definitions over algebraic data types, sets, maps, and integers.
Our implementation runs on a platform combining a constraint solver with a standard virtual machine. For constraint solving we use an algorithm that handles recursive function definitions through fair function unrolling and builds upon the state-of-the art SMT solver Z3. We evaluate Kaplan on examples ranging from enumeration of data structures to execution of declarative specifications. We found Kaplan promising because it is expressive, supporting a range of problem domains, while enabling full-speed execution of programs that do not rely on constraint programming.

Supplementary Material

JPG File (popl_2b_3.jpg)
ZIP File (popl150.zip)
The Kaplan system is available from http://lara.epfl.ch. The file ACMDLExamples.scala can readily be compiled and run using Kaplan. It contains examples from the paper: Ali Sinan Köksal, Viktor Kuncak, Philippe Suter, "Constraints as Control", ACM SIGPLAN POPL 2012. as well as some more.
MP4 File (popl_2b_3.mp4)

References

[1]
H. Aït-Kaci. Warren's Abstract Machine: A Tutorial Reconstruction. MIT Press, 1991.
[2]
S. Antoy. Definitional trees. In ALP, pages 143--157, 1992.
[3]
S. Antoy and M. Hanus. Functional logic programming. CACM, 53 (4): 74--85, 2010.
[4]
K. R. Apt and M. Wallace. Constraint logic programming using Eclipse. Cambridge University Press, 2007.
[5]
K. R. Apt, J. Brunekreef, V. Partington, and A. Schaerf. Alma-O: An imperative language that supports declarative programming. TOPLAS, 20 (5): 1014--1066, 1998.
[6]
R.-J. Back and J. von Wright. Refinement Calculus. Springer-Verlag, 1998.
[7]
T. Ball, D. Hoffman, F. Ruskey, R. Webber, and L. J. White. State generation and automated class testing. Softw. Test., Verif. Reliab., 10 (3), 2000.
[8]
C. Barrett and C. Tinelli. CVC3. In CAV, volume 4590 of LNCS, 2007.
[9]
G. M. Bierman, A. D. Gordon, C. Hritcu, and D. E. Langworthy. Semantic subtyping with an SMT solver. In ICFP, pages 105--116, 2010.
[10]
A. Blass, Y. Gurevich, and D. Kozen. A zero-one law for logic with a fixed-point operator. Inf. Control, 67, October 1986.
[11]
C. Boyapati, S. Khurshid, and D. Marinov. Korat: Automated testing based on Java predicates. In Proc. International Symposium on Software Testing and Analysis, pages 123--133, July 2002.
[12]
B. Braßel, M. Hanus, and M. Müller. High-level database programming in Curry. In PADL, pages 316--332, 2008.
[13]
K. Claessen and J. Hughes. Quickcheck: a lightweight tool for random testing of haskell programs. In ICFP, pages 268--279, 2000.
[14]
A. Colmerauer, H. Kanoui, and M. V. Caneghem. Last steps towards an ultimate PROLOG. In IJCAI, pages 947--948, 1981.
[15]
R. DeLine and K. R. M. Leino. BoogiePL: A typed procedural language for checking object-oriented programs. Technical Report MSR-TR-2005--70, Microsoft Research, March 2005.
[16]
B. Demsky and M. C. Rinard. Automatic detection and repair of errors in data structures. In OOPSLA, pages 78--95, 2003.
[17]
D. Detlefs, G. Nelson, and J. B. Saxe. Simplify: a theorem prover for program checking. J. ACM, 52 (3): 365--473, 2005.
[18]
E. W. Dijkstra. Guarded commands, nondeterminacy and formal derivation of programs. Commun. ACM, 18 (8): 453--457, 1975.
[19]
B. Dutertre and L. \noopsortMourade Moura. The Yices SMT solver, 2006. http://yices.csl.sri.com/tool-paper.pdf.
[20]
B. Elkarablieh and S. Khurshid. Juzi: a tool for repairing complex data structures. In ICSE, pages 855--858, 2008.
[21]
S. Fischer, O. Kiselyov, and C. Shan. Purely functional lazy non-deterministic programming. In ICFP, volume 44, pages 11--22, 2009.
[22]
H. Ganzinger, G. Hagen, R. Nieuwenhuis, A. Oliveras, and C. Tinelli. DPLL(T): Fast decision procedures. In CAV, pages 175--188, 2004.
[23]
I. P. Gent, C. Jefferson, and I. Miguel. MINION: A fast, scalable, constraint solver. In European Conference on Artificial Intelligence, pages 98--102. IOS Press, 2006.
[24]
M. Gligoric, T. Gvero, V. Jagannath, S. Khurshid, V. Kuncak, and D. Marinov. Test generation through programming in udita. In ICSE (1), pages 225--234, 2010.
[25]
M. Grabmüller and P. Hofstedt. Turtle: A constraint imperative programming language. In Innovative Techniques and Applications of Artificial Intelligence, 2003.
[26]
S. Gulwani, S. Jha, A. Tiwari, and R. Venkatesan. Synthesis of loop-free programs. In PLDI, pages 62--73, 2011.
[27]
M. Hanus. Type-oriented construction of web user interfaces. In PPDP, pages 27--38, 2006.
[28]
M. Hanus and C. Kluß. Declarative programming of user interfaces. In PADL, pages 16--30, 2009.
[29]
D. Jackson. Structuring Z specifications with views. ACM Transactions on Software Engineering and Methodology, 4 (4), October 1995.
[30]
D. Jackson. Alloy: a lightweight object modelling notation. ACM Trans. Softw. Eng. Methodol., 11 (2): 256--290, 2002.
[31]
J. Jaffar and J.-L. Lassez. Constraint logic programming. In POPL, 1987.
[32]
J. C. King. A Program Verifier. PhD thesis, Carnegie Mellon University, 1970.
[33]
A. S. Köksal, V. Kuncak, and P. Suter. Scala to the power of Z3: Integrating SMT and programming (system description). In CADE, pages 400--406, 2011.
[34]
R. A. Kowalski and D. Kuehner. Linear resolution with selection function. Artif. Intell., 2 (3/4): 227--260, 1971.
[35]
V. Kuncak, M. Mayer, R. Piskac, and P. Suter. Complete functional synthesis. In PLDI, pages 316--329, 2010.
[36]
L. Lamport. Specifying Systems: The TLA
[37]
Language and Tools for Hardware and Software Engineers. Addison-Wessley, 2002.
[38]
G. Lopez, B. Freeman-Benson, and A. Borning. Kaleidoscope: A constraint imperative programming language. In Constraint Programming, pages 313--329. Springer-Verlag, 1994.
[39]
M. Z. Malik, J. H. Siddiqui, and S. Khurshid. Constraint-based program debugging using data structure repair. In ICST, pages 190--199, 2011.
[40]
Z. Manna and R. Waldinger. A deductive approach to program synthesis. ACM Trans. Program. Lang. Syst., 2 (1): 90--121, 1980. ISSN 0164-0925. http://doi.acm.org/10.1145/357084.357090.
[41]
F. Maric and P. Janicic. Urbiva: Uniform reduction to bit-vector arithmetic. In IJCAR, pages 346--352, 2010.
[42]
E. Michael Hanus. Curry: An integrated functional logic language. http://www.curry-language.org, 2006. vers. 0.8.2.
[43]
A. Milicevic, D. Rayside, K. Yessenov, and D. Jackson. Unifying execution of imperative and declarative code. In ICSE, pages 511--520, 2011.
[44]
C. Morgan. Programming from Specifications (2nd ed.). Prentice-Hall, Inc., 1994.
[45]
L. Mourade Moura and N. Bjørner. Z3: An efficient SMT solver. In TACAS, 2008.
[46]
G. Nelson. Techniques for program verification. Technical report, XEROX Palo Alto Research Center, 1981.
[47]
G. Nelson and D. C. Oppen. Fast decision procedures based on congruence closure. Journal of the ACM (JACM), 27 (2): 356--364, 1980. ISSN 0004--5411. http://doi.acm.org/10.1145/322186.322198.
[48]
N. Nethercote, P. Stuckey, R. Becket, S. Brand, G. Duck, and G. Tack. MiniZinc: Towards a standard CP modelling language. Principles and Practice of Constraint Programming, pages 529--543, 2007.
[49]
R. Nilsson. Scalacheck user guide. http://code.google.com/p/scalacheck/wiki/UserGuide, 2011.
[50]
M. Odersky. Contracts in Scala. In International Conference on Runtime Verification. Springer LNCS, 2010.
[51]
M. Odersky, L. Spoon, and B. Venners. Programming in Scala: a comprehensive step-by-step guide. Artima Press, 2008.
[52]
D. Overton, Z. Somogyi, and P. J. Stuckey. Constraint-based mode analysis of Mercury. In ACM SIGPLAN Workshop on Principles and practice of declarative programming (PPDI), 2002.
[53]
L. C. Paulson, T. Nipkow, et al. Isabelle theorem prover - official website. http://www.cl.cam.ac.uk/Research/HVG/Isabelle.
[54]
A. Pnueli and R. Rosner. On the synthesis of a reactive module. In POPL, 1989.
[55]
A. Riesco and J. Rodrıguez-Hortalá. Programming with singular and plural non-deterministic functions. In PEPM, pages 83--92, 2010.
[56]
H. Samimi, E. D. Aung, and T. D. Millstein. Falling back on executable specifications. In ECOOP, pages 552--576, 2010.
[57]
T. Schrijvers, P. J. Stuckey, and P. Wadler. Monadic constraint programming. J. Funct. Program., 19 (6): 663--697, 2009.
[58]
J. P. M. Silva and K. A. Sakallah. GRASP - a new search algorithm for satisfiability. In ICCAD, pages 220--227, 1996.
[59]
A. Solar-Lezama, L. Tancau, R. Bodık, S. A. Seshia, and V. A. Saraswat. Combinatorial sketching for finite programs. In ASPLOS, 2006.
[60]
P. Suter, M. Dotta, and V. Kuncak. Decision procedures for algebraic data types with abstractions. In ACM SIGPLAN POPL, 2010.
[61]
P. Suter, A. S. Köksal, and V. Kuncak. Satisfiability modulo recursive programs. In Static Analysis Symposium (SAS), 2011.
[62]
G. Tack. Constraint Propagation - Models, Techniques, Implementation. PhD thesis, Saarland University, 2009.
[63]
The Coq Development Team; INRIA LogiCal Project. The Coq proof assistant - official website. http://coq.inria.fr.
[64]
E. Torlak and D. Jackson. Kodkod: A relational model finder. In Tools and Algorithms for Construction and Analysis of Systems (TACAS), 2007.
[65]
P. Van Roy. Logic programming in Oz with Mozart. In ICLP, 1999.
[66]
R. N. Zaeem and S. Khurshid. Contract-based data structure repair using Alloy. In ECOOP, pages 577--598, 2010.
[67]
L. Zhang, C. F. Madigan, M. W. Moskewicz, and S. Malik. Efficient conflict driven learning in boolean satisfiability solver. In ICCAD, pages 279--285, 2001.

Cited By

View all
  • (2023)Grisette: Symbolic Compilation as a Functional Programming LibraryProceedings of the ACM on Programming Languages10.1145/35712097:POPL(455-487)Online publication date: 11-Jan-2023
  • (2021)Program analysis via efficient symbolic abstractionProceedings of the ACM on Programming Languages10.1145/34854955:OOPSLA(1-32)Online publication date: 15-Oct-2021
  • (2020)A General Framework for Compositional Network ModelingProceedings of the 19th ACM Workshop on Hot Topics in Networks10.1145/3422604.3425930(8-15)Online publication date: 4-Nov-2020
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
POPL '12: Proceedings of the 39th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages
January 2012
602 pages
ISBN:9781450310833
DOI:10.1145/2103656
  • cover image ACM SIGPLAN Notices
    ACM SIGPLAN Notices  Volume 47, Issue 1
    POPL '12
    January 2012
    569 pages
    ISSN:0362-1340
    EISSN:1558-1160
    DOI:10.1145/2103621
    Issue’s Table of Contents
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Sponsors

In-Cooperation

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 25 January 2012

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. constraint programming
  2. embedded domain-specific languages
  3. executable specifications
  4. non-determinism
  5. satisfiability modulo theories
  6. scala

Qualifiers

  • Research-article

Conference

POPL '12
Sponsor:

Acceptance Rates

Overall Acceptance Rate 860 of 4,328 submissions, 20%

Upcoming Conference

POPL '26

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)19
  • Downloads (Last 6 weeks)2
Reflects downloads up to 25 Feb 2025

Other Metrics

Citations

Cited By

View all
  • (2023)Grisette: Symbolic Compilation as a Functional Programming LibraryProceedings of the ACM on Programming Languages10.1145/35712097:POPL(455-487)Online publication date: 11-Jan-2023
  • (2021)Program analysis via efficient symbolic abstractionProceedings of the ACM on Programming Languages10.1145/34854955:OOPSLA(1-32)Online publication date: 15-Oct-2021
  • (2020)A General Framework for Compositional Network ModelingProceedings of the 19th ACM Workshop on Hot Topics in Networks10.1145/3422604.3425930(8-15)Online publication date: 4-Nov-2020
  • (2019)G2Q: Haskell constraint solvingProceedings of the 12th ACM SIGPLAN International Symposium on Haskell10.1145/3331545.3342590(44-57)Online publication date: 8-Aug-2019
  • (2019)Lazy counterfactual symbolic executionProceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Implementation10.1145/3314221.3314618(411-424)Online publication date: 8-Jun-2019
  • (2019)Symbolic computation of differential equivalencesTheoretical Computer Science10.1016/j.tcs.2019.03.018Online publication date: Mar-2019
  • (2017)Bonsai: synthesis-based reasoning for type systemsProceedings of the ACM on Programming Languages10.1145/31581502:POPL(1-34)Online publication date: 27-Dec-2017
  • (2017)Symbolic types for lenient symbolic executionProceedings of the ACM on Programming Languages10.1145/31581282:POPL(1-29)Online publication date: 27-Dec-2017
  • (2017)A solver-aided language for test input generationProceedings of the ACM on Programming Languages10.1145/31339151:OOPSLA(1-24)Online publication date: 12-Oct-2017
  • (2017)LOIS: syntax and semanticsACM SIGPLAN Notices10.1145/3093333.300987652:1(586-598)Online publication date: 1-Jan-2017
  • Show More Cited By

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media