Explicit Binds: Effortless Efficiency with and without Trees

  • Tarmo Uustalu
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7294)


We demonstrate a simple and robust program transformation technique that can improve asymptotic time complexity of data-manipulating programs (e.g., produce a linear-time list reversal function from the obvious quadratic one). In the version of the present paper, it applies to monadic inductive datatypes and can be stated in two flavors, through a datatype representation, with an explicit (“frozen”) bind constructor and a special associated defining clause for the fold function, and in a functional form (generalized Church numerals), with a special definition of the bind function in terms of the build constructor. The technique explicates, systematizes, combines and scales a number of ideas known from the literature, achieving a new level of generality.


Prefix Verse Meijer RoseX 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Abadi, M., Cardelli, L., Curien, P.-L., Levy, J.-J.: Explicit substitutions. J. of Funct. Program. 1(4), 375–416 (1991)MathSciNetMATHCrossRefGoogle Scholar
  2. 2.
    Fegaras, L.: Using the parametricity theorem for program fusion. Tech. report CSE-96-001. Oregon Grad. Inst. (1996)Google Scholar
  3. 3.
    Ghani, N., Johann, P.: Short cut fusion for effects. In: Achten, P., Koopman, P., Morazán, M. (eds.) Trends in Functional Programming, vol. 9, pp. 113–128. Intellect, Bristol (2009)Google Scholar
  4. 4.
    Ghani, N., Uustalu, T., Vene, V.: Build, Augment and Destroy, Universally. In: Chin, W.-N. (ed.) APLAS 2004. LNCS, vol. 3302, pp. 327–347. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  5. 5.
    Ghani, N., Uustalu, T., Vene, V.: Generalizing the augment combinator. In: Loidl, H.-W. (ed.) Trends in Functional Programming, vol. 5, pp. 65–78. Intellect, Bristol (2006)Google Scholar
  6. 6.
    Gill, A.: Cheap Deforestation for Non-strict Functional Languages. PhD thesis. University of Glasgow (1996)Google Scholar
  7. 7.
    Gill, A., Hutton, G.: The worker/wrapper transformation. J. of Funct. Program. 19(2), 227–251 (2009)MATHCrossRefGoogle Scholar
  8. 8.
    Gill, A., Launchbury, J., Peyton Jones, S.L.: A short cut to deforestation. In: Conf. Record of 6th ACM SIGPLAN/SIGARCH Int. Conf. on Functional Programming Languages and Computer Architecture, FPCA 1993, Copenhagen, pp. 223–232. ACM Press, New York (1993)CrossRefGoogle Scholar
  9. 9.
    Hughes, J.: A novel representation of lists and its application to the function ‘reverse’. Inf. Process. Lett. 22(3), 141–144 (1986)CrossRefGoogle Scholar
  10. 10.
    Hutton, G., Jaskelioff, M., Gill, A.: Factorising folds for faster functions. J. of Funct. Program. 20(3-4), 353–373 (2010)MATHCrossRefGoogle Scholar
  11. 11.
    Johann, P.: A generalization of short-cut fusion and its correctness proof. Higher-Order and Symb. Comput. 15(4), 273–300 (2002)MATHCrossRefGoogle Scholar
  12. 12.
    Johann, P.: Short-cut fusion is correct. J. of Funct. Program. 13(4), 797–814 (2003)MathSciNetMATHCrossRefGoogle Scholar
  13. 13.
    Jürgensen, C., Vogler, H.: Syntactic composition of top-down tree transducers is short cut fusion. Math. Struct. in Comput. Sci. 14(2), 215–282 (2004)MATHCrossRefGoogle Scholar
  14. 14.
    Kmett, E.: Kan extensions 1–3. Posts on the author’s blog ‘The Comonad.Reader’ (2008), http://comonad.com/reader/
  15. 15.
    Kmett, E.: Free monads for less 1–3. Posts on the author’s blog ‘The Comonad.Reader’ (2011), http://comonad.com/reader/
  16. 16.
    Kühnemann, A.: Comparison of Deforestation Techniques for Functional Programs and for Tree Transducers. In: Middeldorp, A., Sato, T. (eds.) FLOPS 1999. LNCS, vol. 1722, pp. 114–130. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  17. 17.
    Kühnemann, A., Maletti, A.: The Substitution Vanishes. In: Johnson, M., Vene, V. (eds.) AMAST 2006. LNCS, vol. 4019, pp. 173–188. Springer, Heidelberg (2006)CrossRefGoogle Scholar
  18. 18.
    Manzino, C., Pardo, A.: Shortcut fusion of monadic programs. J. of Univ. Comput. Sci. 14(21), 3431–3446 (2008)MATHGoogle Scholar
  19. 19.
    Pavlovic, D.: Logic of build fusion. Techn. report KES.U.00.9. Kestrel Inst. (2000)Google Scholar
  20. 20.
    Peyton Jones, S.L., Launchbury, J.: Unboxed Values as First Class Citizens in a Non-strict Functional Language. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 636–666. Springer, Heidelberg (1991)CrossRefGoogle Scholar
  21. 21.
    Seidel, D., Voigtländer, J.: Improvements for free. In: Massink, M., Norman, G. (eds.) Proc. of 9th Wksh. on Quantitative Aspects of Programming Languages, QAPL 2011, Saarbrücken. Electron. Proc. in Theor. Comput. Sci., vol. 57, pp. 89–103. Elsevier, Amsterdam (2011)Google Scholar
  22. 22.
    Svenningsson, J.: Shortcut fusion for accumulating parameters & zip-like functions. In: Proc. of 7th ACM SIGPLAN Int. Conf. on Functional Programming, ICFP 2002, Pittsburgh, PA, pp. 124–132. ACM Press, New York (2002)CrossRefGoogle Scholar
  23. 23.
    Takano, A., Meijer, E.: Shortcut deforestation in calculational form. In: Conf. Record of 7th ACM SIGPLAN/SIGARCH Conf. on Functional Programming Languages and Computer Architecture, FPCA 1995, La Jolla, pp. 306–316. ACM Press, New York (1995)Google Scholar
  24. 24.
    Uustalu, T.: Generalizing substitution. Theor. Inform. and Appl. 37(4), 315–336 (2003)MathSciNetMATHCrossRefGoogle Scholar
  25. 25.
    Uustalu, T., Vene, V.: The Essence of Dataflow Programming. In: Horváth, Z. (ed.) CEFP 2005. LNCS, vol. 4164, pp. 135–167. Springer, Heidelberg (2006)CrossRefGoogle Scholar
  26. 26.
    Voigtländer, J.: Asymptotic Improvement of Computations over Free Monads. In: Audebaud, P., Paulin-Mohring, C. (eds.) MPC 2008. LNCS, vol. 5133, pp. 388–403. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  27. 27.
    Voigtländer, J.: Concatenate, reverse and map vanish for free. In: Proc. of 7th Int. Conf. on Functional Programming, ICFP 2002, Pittsburgh, PA, pp. 14–25. ACM Press, New York (2002)Google Scholar
  28. 28.
    Wadler, P.: Deforestation: transforming programs to eliminate trees. Theor. Comput. Sci. 73(2), 231–248 (1990)MathSciNetMATHCrossRefGoogle Scholar
  29. 29.
    Wadler, P.: Recursive types for free! Unpublished note (1990)Google Scholar
  30. 30.
    Wadler, P.: The concatenate vanishes. Unpublished note (1987, updated 1989)Google Scholar
  31. 31.
    Wadler, P.: Theorems for free! In: Proc. of 4th Int. Conf. on Functional Programming Languages and Computer Architecture, FPCA 1989, London, pp. 347–359. ACM Press, New York (1989)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Tarmo Uustalu
    • 1
  1. 1.Institute of CyberneticsTallinn University of TechnologyTallinnEstonia

Personalised recommendations