Abstract
A domain-specific language (DSL) is a specification language designed to facilitate programming in a certain application domain. A well-designed DSL reflects the natural structure of the modeled domain, enforces abstraction, and its implementation exploits domain-specific properties for safety and performance. Expounding on the latter, in this paper we describe a simple, but powerful method for gradually enhancing a base implementation with computational performance improvements. It consists of adding constructors for expensive operations if this facilitates asymptotic performance improvements in some contexts, with at most constant-factor overhead. The resulting implementation can be thought of as executing “standard” computation steps from the base implementation interleaved with symbolic computation steps on the newly introduced constructors. Evaluation of constructor expressions is lazy in a strong sense: It does not only delay evaluation by thunkifying its standard evaluation, but performs run-time inspection to evaluate constructor expressions in a nonstandard way.
Extending earlier work by Henglein and Larsen [1] on generic multiset programming we arrive at novel multiset representations with constructors for unions, Cartesian products, scalar multiplication, and mapping binary functions over Cartesian products. We show how the resulting implementation can be used to implement finite probability distributions with exact (rational) probabilities. It supports computing both the expected value and, what we believe to be novel, the variance of random variables over n-ary product distributions efficiently by avoiding enumeration of the product sample space.
This research has been partially supported by the Danish National Advanced Technology Foundation under Projects 3d generation Enterprise Resource Planning Systems (3gERP) and by the Danish Strategic Research Council for the HIPERFIT Research Center (hiperfit.dk).
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
References
Henglein, F., Larsen, K.: Generic multiset programming with discrimination-based joins and symbolic Cartesian products. Higher-Order and Symbolic Computation (HOSC) 23, 337–370 (2010); (Publication date: November 24, 2011)
Trinder, P., Wadler, P.: List comprehensions and the relational calculus. In: Proc. 1988 Glasgow Workshop on Functional Programming, Rothesay, Scotland, pp. 115–123 (August 1988)
Peyton Jones, S., Wadler, P.: Comprehensive comprehensions. In: Proc. 2007 Haskell Workshop, Freiburg, Germany (2007)
Giorgidze, G., Grust, T., Schreiber, T., Weijers, J.: Haskell Boards the Ferry. In: Hage, J., Morazán, M.T. (eds.) IFL 2010. LNCS, vol. 6647, pp. 1–18. Springer, Heidelberg (2011)
Peyton Jones, S.: The Haskell 98 language. J. Functional Programming (JFP) 13(1), 0–146 (2003)
Cheney, J., Hinze, R.: First-class phantom types. CUCIS TR2003-1901, Cornell University (2003)
Xi, H., Chen, C., Chen, G.: Guarded recursive datatype constructors. In: Proc. 30th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 224–235. ACM (2003)
Bentley, J.: Programming pearls: Little languages. Commun. ACM 29(8), 711–721 (1986)
Hudak, P., Peterson, J., Fasel, J.H.: A gentle introduction to Haskell Version 98. Online Tutorial (May 1999)
Henglein, F.: Optimizing relational algebra operations using discrimination-based joins and lazy products. In: Proc. ACM SIGPLAN 2010 Workshop on Partial Evaluation and Program Manipulation, January 18-19, pp. 73–82. ACM, New York (2010); Also DIKU TOPPS D-report no. 611
Henglein, F., Larsen, K.: Generic multiset programming for language-integrated querying. In: Proceedings of the 6th ACM SIGPLAN Workshop on Generic Programming (WGP), pp. 49–60. ACM (2010)
Henglein, F.: Generic top-down discrimination for sorting and partitioning in linear time. Invited Submission to Journal of Functional Programming (JFP) (December 2010)
Selinger, P.G., Astrahan, M.M., Chamberlin, D.D., Lorie, R.A., Price, T.G.: Access path selection in a relational database management system. In: Proc. 1979 ACM SIGMOD Int’l. Conf. on Management of Data, SIGMOD 1979, pp. 23–34. ACM, New York (1979)
Hughes, J.: Generalising monads to arrows. Science of Computer Programming 37(1-3), 67–111 (2000)
Boehm, H.J., Atkinson, R., Plass, M.: Ropes: An alternative to strings. Software: Practice and Experience 25(12), 1315–1330 (1995)
Meertens, L.: Algorithmics–towards programming as a mathematical activity. In: Proc. CWI Symp. on Mathematics and Computer Science, pp. 289–334. North-Holland (1986)
Bird, R.: An introduction to the theory of lists. Technical Report PRG-56, Oxford University (October 1986)
Backhouse, R.: An exploration of the Bird-Meertens formalism. In: STOP Summer School on Constructive Algorithmics (1989)
Meijer, E., Fokkinga, M., Paterson, R.: Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 124–144. Springer, Heidelberg (1991)
Okasaki, C.: Purely Functional Data Structures. Cambridge University Press, Cambridge (1998)
Hughes, J.: A novel representation of lists and its application to the function “reverse”. Information Processing Letters 22, 141–144 (1986)
Kühnemann, A., Glück, R., Kakehi, K.: Relating Accumulative and Non-accumulative Functional Programs. In: Middeldorp, A. (ed.) RTA 2001. LNCS, vol. 2051, pp. 154–168. Springer, Heidelberg (2001)
Voigtländer, J.: Concatenate, reverse and map vanish for free. In: Proc. Int’l. Conf. on Functional Programming (ICFP), Pittsburgh, PA, pp. 14–25 (2002)
Wadler, P.: The concatenate vanishes. Unpublished manuscript (December 1987) (revised November 1989)
Gill, A., Launchbury, J., Jones, S.P.: A short cut to deforestation. In: Proceedings of Functional Programming Languages and Computer Architecture (FPCA), pp. 223–232. ACM Press (1993)
Coutts, D., Leshchinskiy, R., Stewart, D.: Stream fusion: from lists to streams to nothing at all. In: Hinze, R., Ramsey, N. (eds.) ICFP, pp. 315–326. ACM (2007)
Axelsson, E., Claessen, K., Dévai, G., Horváth, Z., Keijzer, K., Lyckegard, B., Persson, A., Sheeran, M., Svenningsson, J., Vajdax, A.: Feldspar: A domain specific language for digital signal processing algorithms. In: Proc. 8th IEEE/ACM Int’l. Conf. on Formal Methods and Models for Codesign (MEMOCODE), pp. 169–178. IEEE (2010)
Chakravarty, M., Keller, G., Lee, S., McDonell, T., Grover, V.: Accelerating Haskell array codes with multicore GPUs. In: Proc. 6th Workshop on Declarative Aspects of Multicore Programming (DAMP), pp. 3–14. ACM (2011)
Keller, G., Chakravarty, M., Leshchinskiy, R., Peyton Jones, S., Lippmeier, B.: Regular, shape-polymorphic, parallel arrays in Haskell. ACM SIGPLAN Notices 45(9), 261–272 (2010)
Emoto, K., Fischer, S., Hu, Z.: Generate, Test, and Aggregate —a Calculation-Based Framework for Systematic Parallel Programming with MapReduce. In: Seidl, H. (ed.) ESOP 2012. LNCS, vol. 7211, pp. 254–273. Springer, Heidelberg (2012)
Ramsey, N., Pfeffer, A.: Stochastic lambda calculus and monads of probability distributions. ACM SIGPLAN Notices 37(1), 154–165 (2002)
Dechter, R.: Bucket elimination: A unifying framework for probabilistic inference. NATO ASI Series D, Behavioural and Social Sciences 89, 75–104 (1998)
Erwig, M., Kollmansberger, S.: Probabilistic functional programming in Haskell (functional pearl). J. Functional Programming 16(01), 21–34 (2006)
Larsen, K.F.: Memory efficient implementation of probability monads. Unpublished manuscript (August 2011)
Kiselyov, O., Shan, C.-C.: Embedded Probabilistic Programming. In: Taha, W.M. (ed.) DSL 2009. LNCS, vol. 5658, pp. 360–384. Springer, Heidelberg (2009)
Park, S., Pfenning, F., Thrun, S.: A probabilistic language based on sampling functions. ACM TOPLAS 31(1), 4 (2008)
Mogensen, T.: Troll, a language for specifying dice-rolls. In: Proc. 2009 ACM Symp. on Applied Computing (SAC), pp. 1910–1915. ACM (2009)
Bhat, S., Agarwal, A., Vuduc, R., Gray, A.: A type theory for probability density functions. In: Proc. 39th SIGACT-SIGPLAN Symp. on Principles of Programming Languages (POPL). ACM press (January 2012)
Grust, T., Sakr, S., Teubner, J.: XQuery on SQL hosts. In: Proc. 30th Int’l. Conf. on Very Large Bata Bases, vol. 30, p. 263 (2004)
Grust, T.: Purely relational FLWORs. In: Proc. XIME-P (2005)
Grust, T., Rittinger, J., Schreiber, T.: Avalanche-safe LINQ compilation. Proc. VLDB Endow 3, 162–172 (2010)
Swierstra, W.: Data types à la carte. J. Functional Programming 18(4), 423–436 (2008)
Bahr, P., Hvitved, T.: Compositional data types. In: Proc. 7th ACM SIGPLAN Workshop on Generic Programming (WGP), pp. 83–94. ACM (2011)
Bahr, P., Hvitved, T.: Parametric compositional data types. In: Proc. Mathematically Structured Functional Programming, MSFP (2012)
Clavel, M., Durán, F., Eker, S., Lincoln, P., Martí-Oliet, N., Meseguer, J., Quesada, J.: Maude: Specification and programming in rewriting logic. Theoretical Computer Science 285(2), 187–243 (2002)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2012 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Henglein, F. (2012). Dynamic Symbolic Computation for Domain-Specific Language Implementation. In: Vidal, G. (eds) Logic-Based Program Synthesis and Transformation. LOPSTR 2011. Lecture Notes in Computer Science, vol 7225. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-32211-2_2
Download citation
DOI: https://doi.org/10.1007/978-3-642-32211-2_2
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-32210-5
Online ISBN: 978-3-642-32211-2
eBook Packages: Computer ScienceComputer Science (R0)