[go: up one dir, main page]

Skip to main content

Free Theorems Simply, via Dinaturality

  • Conference paper
  • First Online:
Declarative Programming and Knowledge Management (INAP 2019, WLP 2019, WFLP 2019)

Abstract

Free theorems are a popular tool in reasoning about parametrically polymorphic code. They are also of instructive use in teaching. Their derivation, though, can be tedious, as it involves unfolding a lot of definitions, then hoping to be able to simplify the resulting logical formula to something nice and short. Even in a mechanised generator it is not easy to get the right heuristics in place to achieve good outcomes. Dinaturality is a categorical abstraction that captures many instances of free theorems. Arguably, its origins are more conceptually involved to explain, though, and generating useful statements from it also has its pitfalls. We present a simple approach for obtaining dinaturality-related free theorems from the standard formulation of relational parametricity in a rather direct way. It is conceptually appealing and easy to control and implement, as the provided Haskell code shows.

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

Access this chapter

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

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 EPUB and 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

Similar content being viewed by others

Notes

  1. 1.

    Something we will not mention again and again is that \( g \) is also itself non-\(\bot \). Disregarding types that contain only \(\bot \), this follows from totality of \( g \) anyway.

  2. 2.

    Additional code for parsing input strings into type expressions and pretty-printing generated theorem expressions back into pleasingly looking strings is of comparable complexity between the different generators.

References

  1. http://hackage.haskell.org/package/free-theorems. Accessed Sept 2019

  2. http://free-theorems.nomeata.de. Accessed Sept 2019

  3. http://hackage.haskell.org/package/lambdabot-haskell-plugins. Accessed Sept 2019

  4. http://hackage.haskell.org/package/ft-generator. Accessed Sept 2019

  5. Bainbridge, E., Freyd, P., Scedrov, A., Scott, P.: Functorial polymorphism. Theor. Comput. Sci. 70(1), 35–64 (1990)

    Article  MathSciNet  Google Scholar 

  6. Berger, U., Schwichtenberg, H.: An inverse of the evaluation functional for typed lambda-calculus. In: Logic in Computer Science, Proceedings, pp. 203–211. IEEE Press (1991)

    Google Scholar 

  7. Gill, A., Launchbury, J., Peyton Jones, S.: A short cut to deforestation. In: Functional Programming Languages and Computer Architecture, Proceedings, pp. 223–232. ACM Press (1993)

    Google Scholar 

  8. Hackett, J., Hutton, G.: Programs for cheap! In: Logic in Computer Science, Proceedings, pp. 115–126. IEEE Press (2015)

    Google Scholar 

  9. Johann, P., Voigtländer, J.: Free theorems in the presence of seq. In: Principles of Programming Languages, Proceedings, pp. 99–110. ACM Press (2004)

    Google Scholar 

  10. Mehner, S., Seidel, D., Straßburger, L., Voigtländer, J.: Parametricity and proving free theorems for functional-logic languages. In: Principles and Practice of Declarative Programming, Proceedings, pp. 19–30. ACM Press (2014)

    Google Scholar 

  11. Pfenning, F., Elliott, C.: Higher-order abstract syntax. In: Programming Language Design and Implementation, Proceedings, pp. 199–208. ACM Press (1988)

    Google Scholar 

  12. Reynolds, J.: Types, abstraction and parametric polymorphism. In: Information Processing, Proceedings, pp. 513–523. Elsevier (1983)

    Google Scholar 

  13. Stenger, F., Voigtländer, J.: Parametricity for Haskell with imprecise error semantics. In: Curien, P.-L. (ed.) TLCA 2009. LNCS, vol. 5608, pp. 294–308. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-02273-9_22

    Chapter  Google Scholar 

  14. Wadler, P.: Theorems for free! In: Functional Programming Languages and Computer Architecture, Proceedings, pp. 347–359. ACM Press (1989)

    Google Scholar 

Download references

Acknowledgements

Many of the ideas here, most notably the conjuring lemma (including that name), but also the criterion proposed in Sect. 3.5, originated during past collaboration with Stefan Mehner.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Janis Voigtländer .

Editor information

Editors and Affiliations

A Implementation

A Implementation

See Sect. 4 for some explanation of the implementation.

Fig. 2.
figure 2

Module \(\mathsf {Generate}\), generation and simplification of free theorems

Fig. 3.
figure 3

Module \(\mathsf {Syntax}\), datatypes for types and different forms of (higher-order abstract syntax) terms, and eta-reduction

Fig. 4.
figure 4

Module \(\mathsf {Main}\), putting the generator together with input and output

Fig. 5.
figure 5

An example session

Rights and permissions

Reprints and permissions

Copyright information

© 2020 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Voigtländer, J. (2020). Free Theorems Simply, via Dinaturality. In: Hofstedt, P., Abreu, S., John, U., Kuchen, H., Seipel, D. (eds) Declarative Programming and Knowledge Management. INAP WLP WFLP 2019 2019 2019. Lecture Notes in Computer Science(), vol 12057. Springer, Cham. https://doi.org/10.1007/978-3-030-46714-2_16

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-46714-2_16

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-46713-5

  • Online ISBN: 978-3-030-46714-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics