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.
Supplemental Material
Available for Download
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.
- H. Aït-Kaci. Warren's Abstract Machine: A Tutorial Reconstruction. MIT Press, 1991. Google Scholar
Digital Library
- S. Antoy. Definitional trees. In ALP, pages 143--157, 1992. Google Scholar
Digital Library
- S. Antoy and M. Hanus. Functional logic programming. CACM, 53 (4): 74--85, 2010. Google Scholar
Digital Library
- K. R. Apt and M. Wallace. Constraint logic programming using Eclipse. Cambridge University Press, 2007. Google Scholar
Digital Library
- 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. Google Scholar
Digital Library
- R.-J. Back and J. von Wright. Refinement Calculus. Springer-Verlag, 1998.Google Scholar
- 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.Google Scholar
- C. Barrett and C. Tinelli. CVC3. In CAV, volume 4590 of LNCS, 2007. Google Scholar
Digital Library
- G. M. Bierman, A. D. Gordon, C. Hritcu, and D. E. Langworthy. Semantic subtyping with an SMT solver. In ICFP, pages 105--116, 2010. Google Scholar
Digital Library
- A. Blass, Y. Gurevich, and D. Kozen. A zero-one law for logic with a fixed-point operator. Inf. Control, 67, October 1986. Google Scholar
Digital Library
- 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. Google Scholar
Digital Library
- B. Braßel, M. Hanus, and M. Müller. High-level database programming in Curry. In PADL, pages 316--332, 2008. Google Scholar
Digital Library
- K. Claessen and J. Hughes. Quickcheck: a lightweight tool for random testing of haskell programs. In ICFP, pages 268--279, 2000. Google Scholar
Digital Library
- A. Colmerauer, H. Kanoui, and M. V. Caneghem. Last steps towards an ultimate PROLOG. In IJCAI, pages 947--948, 1981. Google Scholar
Digital Library
- 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.Google Scholar
- B. Demsky and M. C. Rinard. Automatic detection and repair of errors in data structures. In OOPSLA, pages 78--95, 2003. Google Scholar
Digital Library
- D. Detlefs, G. Nelson, and J. B. Saxe. Simplify: a theorem prover for program checking. J. ACM, 52 (3): 365--473, 2005. Google Scholar
Digital Library
- E. W. Dijkstra. Guarded commands, nondeterminacy and formal derivation of programs. Commun. ACM, 18 (8): 453--457, 1975. Google Scholar
Digital Library
- B. Dutertre and L. \noopsortMourade Moura. The Yices SMT solver, 2006. http://yices.csl.sri.com/tool-paper.pdf.Google Scholar
- B. Elkarablieh and S. Khurshid. Juzi: a tool for repairing complex data structures. In ICSE, pages 855--858, 2008. Google Scholar
Digital Library
- S. Fischer, O. Kiselyov, and C. Shan. Purely functional lazy non-deterministic programming. In ICFP, volume 44, pages 11--22, 2009. Google Scholar
Digital Library
- H. Ganzinger, G. Hagen, R. Nieuwenhuis, A. Oliveras, and C. Tinelli. DPLL(T): Fast decision procedures. In CAV, pages 175--188, 2004.Google Scholar
- 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. Google Scholar
Digital Library
- 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. Google Scholar
Digital Library
- M. Grabmüller and P. Hofstedt. Turtle: A constraint imperative programming language. In Innovative Techniques and Applications of Artificial Intelligence, 2003.Google Scholar
- S. Gulwani, S. Jha, A. Tiwari, and R. Venkatesan. Synthesis of loop-free programs. In PLDI, pages 62--73, 2011. Google Scholar
Digital Library
- M. Hanus. Type-oriented construction of web user interfaces. In PPDP, pages 27--38, 2006. Google Scholar
Digital Library
- M. Hanus and C. Kluß. Declarative programming of user interfaces. In PADL, pages 16--30, 2009. Google Scholar
Digital Library
- D. Jackson. Structuring Z specifications with views. ACM Transactions on Software Engineering and Methodology, 4 (4), October 1995. Google Scholar
Digital Library
- D. Jackson. Alloy: a lightweight object modelling notation. ACM Trans. Softw. Eng. Methodol., 11 (2): 256--290, 2002. Google Scholar
Digital Library
- J. Jaffar and J.-L. Lassez. Constraint logic programming. In POPL, 1987. Google Scholar
Digital Library
- J. C. King. A Program Verifier. PhD thesis, Carnegie Mellon University, 1970. Google Scholar
Digital Library
- 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. Google Scholar
Digital Library
- R. A. Kowalski and D. Kuehner. Linear resolution with selection function. Artif. Intell., 2 (3/4): 227--260, 1971.Google Scholar
Cross Ref
- V. Kuncak, M. Mayer, R. Piskac, and P. Suter. Complete functional synthesis. In PLDI, pages 316--329, 2010. Google Scholar
Digital Library
- L. Lamport. Specifying Systems: The TLAGoogle Scholar
- Language and Tools for Hardware and Software Engineers. Addison-Wessley, 2002.Google Scholar
- G. Lopez, B. Freeman-Benson, and A. Borning. Kaleidoscope: A constraint imperative programming language. In Constraint Programming, pages 313--329. Springer-Verlag, 1994.Google Scholar
- M. Z. Malik, J. H. Siddiqui, and S. Khurshid. Constraint-based program debugging using data structure repair. In ICST, pages 190--199, 2011. Google Scholar
Digital Library
- 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. Google Scholar
Digital Library
- F. Maric and P. Janicic. Urbiva: Uniform reduction to bit-vector arithmetic. In IJCAR, pages 346--352, 2010. Google Scholar
Digital Library
- E. Michael Hanus. Curry: An integrated functional logic language. http://www.curry-language.org, 2006. vers. 0.8.2.Google Scholar
- A. Milicevic, D. Rayside, K. Yessenov, and D. Jackson. Unifying execution of imperative and declarative code. In ICSE, pages 511--520, 2011. Google Scholar
Digital Library
- C. Morgan. Programming from Specifications (2nd ed.). Prentice-Hall, Inc., 1994. Google Scholar
Digital Library
- L. Mourade Moura and N. Bjørner. Z3: An efficient SMT solver. In TACAS, 2008. Google Scholar
Digital Library
- G. Nelson. Techniques for program verification. Technical report, XEROX Palo Alto Research Center, 1981.Google Scholar
- 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. Google Scholar
Digital Library
- 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. Google Scholar
Digital Library
- R. Nilsson. Scalacheck user guide. http://code.google.com/p/scalacheck/wiki/UserGuide, 2011.Google Scholar
- M. Odersky. Contracts in Scala. In International Conference on Runtime Verification. Springer LNCS, 2010. Google Scholar
Digital Library
- M. Odersky, L. Spoon, and B. Venners. Programming in Scala: a comprehensive step-by-step guide. Artima Press, 2008. Google Scholar
Digital Library
- 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. Google Scholar
Digital Library
- L. C. Paulson, T. Nipkow, et al. Isabelle theorem prover - official website. http://www.cl.cam.ac.uk/Research/HVG/Isabelle.Google Scholar
- A. Pnueli and R. Rosner. On the synthesis of a reactive module. In POPL, 1989. Google Scholar
Digital Library
- A. Riesco and J. Rodrıguez-Hortalá. Programming with singular and plural non-deterministic functions. In PEPM, pages 83--92, 2010. Google Scholar
Digital Library
- H. Samimi, E. D. Aung, and T. D. Millstein. Falling back on executable specifications. In ECOOP, pages 552--576, 2010. Google Scholar
Digital Library
- T. Schrijvers, P. J. Stuckey, and P. Wadler. Monadic constraint programming. J. Funct. Program., 19 (6): 663--697, 2009. Google Scholar
Digital Library
- J. P. M. Silva and K. A. Sakallah. GRASP - a new search algorithm for satisfiability. In ICCAD, pages 220--227, 1996. Google Scholar
Digital Library
- A. Solar-Lezama, L. Tancau, R. Bodık, S. A. Seshia, and V. A. Saraswat. Combinatorial sketching for finite programs. In ASPLOS, 2006. Google Scholar
Digital Library
- P. Suter, M. Dotta, and V. Kuncak. Decision procedures for algebraic data types with abstractions. In ACM SIGPLAN POPL, 2010. Google Scholar
Digital Library
- P. Suter, A. S. Köksal, and V. Kuncak. Satisfiability modulo recursive programs. In Static Analysis Symposium (SAS), 2011. Google Scholar
Digital Library
- G. Tack. Constraint Propagation - Models, Techniques, Implementation. PhD thesis, Saarland University, 2009.Google Scholar
- The Coq Development Team; INRIA LogiCal Project. The Coq proof assistant - official website. http://coq.inria.fr.Google Scholar
- E. Torlak and D. Jackson. Kodkod: A relational model finder. In Tools and Algorithms for Construction and Analysis of Systems (TACAS), 2007. Google Scholar
Digital Library
- P. Van Roy. Logic programming in Oz with Mozart. In ICLP, 1999. Google Scholar
Digital Library
- R. N. Zaeem and S. Khurshid. Contract-based data structure repair using Alloy. In ECOOP, pages 577--598, 2010. Google Scholar
Digital Library
- 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. Google Scholar
Digital Library
Index Terms
Constraints as control
Recommendations
Constraints as control
POPL '12: Proceedings of the 39th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languagesWe 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 ...
Squid: type-safe, hygienic, and reusable quasiquotes
SCALA 2017: Proceedings of the 8th ACM SIGPLAN International Symposium on ScalaQuasiquotes have been shown to greatly simplify the task of metaprogramming. This is in part because they hide the data structures of the intermediate representation (IR), instead allowing metaprogrammers to use the concrete syntax of the language they ...
StreamJIT: a commensal compiler for high-performance stream programming
OOPSLA '14: Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & ApplicationsThere are many domain libraries, but despite the performance benefits of compilation, domain-specific languages are comparatively rare due to the high cost of implementing an optimizing compiler. We propose commensal compilation, a new strategy for ...







Comments