Hostname: page-component-76fb5796d-vvkck Total loading time: 0 Render date: 2024-04-25T11:19:25.145Z Has data issue: false hasContentIssue false

Interactive programming in Agda – Objects and graphical user interfaces

Published online by Cambridge University Press:  06 February 2017

ANDREAS ABEL
Affiliation:
Department of Computer Science and Engineering, Gothenburg University, Sweden (e-mail: andreas.abel@gu.se)
STEPHAN ADELSBERGER
Affiliation:
Department of Information Systems and Operations, Vienna University of Economics, Austria (e-mail: sadelsbe@wu.ac.at)
ANTON SETZER
Affiliation:
Department of Computer Science, Swansea University, Swansea SA2 8PP, UK (e-mail: a.g.setzer@swan.ac.uk)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

We develop a methodology for writing interactive and object-based programs (in the sense of Wegner) in dependently typed functional programming languages. The methodology is implemented in the ooAgda library. ooAgda provides a syntax similar to the one used in object-oriented programming languages, thanks to Agda's copattern matching facility. The library allows for the development of graphical user interfaces (GUIs), including the use of action listeners.

Our notion of interactive programs is based on the IO monad defined by Hancock and Setzer, which is a coinductive data type. We use a sized coinductive type which allows us to write corecursive programs in a modular way. Objects are server-side interactive programs that respond to method calls by giving answers and changing their state. We introduce two kinds of objects: simple objects and IO objects. Methods in simple objects are pure, while method calls in IO objects allow for interactions before returning their result. Our approach also allows us to extend interfaces and objects by additional methods.

We refine our approach to state-dependent interactive programs and objects through which we can avoid exceptions. For example, with a state-dependent stack object, we can statically disable the pop method for empty stacks. As an example, we develop the implementation of recursive functions using a safe stack. Using a coinductive notion of object bisimilarity, we verify basic correctness properties of stack objects and show the equivalence of different stack implementations. Finally, we give a proof of concept that our interaction model allows to write GUI programs in a natural way: we present a simple drawing program, and a program which allows the users to move a small spaceship using a button.

Type
Articles
Copyright
Copyright © Cambridge University Press 2017 

References

Abadi, M. & Cardelli, L. (eds). (1996) A Theory of Objects, Monographs in Computer Science. Springer.CrossRefGoogle Scholar
Abbott, M., Altenkirch, T. & Ghani, N. (2003) Categories of containers. In Gordon, A. D. (ed.), Proceedings of the International Conference on Foundations of Software Science and Computation Structure, FOSSACS 2003, Lect. Notes in Comput. Sci., vol. 2620, Springer.Google Scholar
Abel, A. (2007) Mixed inductive/coinductive types and strong normalization. In, Shao, Z. (ed), Proceedings of the 5th Asian Symposium on Programming Languages and Systems, APLAS 2007, Lecture Notes in Computer Science, vol. 4807. Springer, pp. 286301.Google Scholar
Abel, A. (2008) Semi-continuous sized types and termination. Log. Meth. Comput. Sci. 4 (2:3), 133 (CSL'06 special issue).Google Scholar
Abel, A. (2010) MiniAgda: Integrating sized and dependent types. In Bove, A., Komendantskaya, E. & Niqui, M. (eds), Proceedings of the workshop on Partiality and Recursion in Interactive Theorem Provers, PAR 2010, Electronic Proceedings in Theoretical Computer Science, vol. 43, pp. 14–28.Google Scholar
Abel, A. (2012) Type-based termination, inflationary fixed-points, and mixed inductive-coinductive types. In Miller, D. & Ésik, Z. (eds), Proceedings of the 8th workshop on Fixed Points in Computer Sciience, FICS 2012 Electronic Proceedings in Theoretical Computer Science, vol. 77, pp. 1–11. Invited talk.Google Scholar
Abel, A. & Altenkirch, T. (2002) A predicative analysis of structural recursion. J. Func. Program. 12 (1), 141.Google Scholar
Abel, A. & Pientka, B. (2013) Wellfounded recursion with copatterns: A unified approach to termination and productivity. In Morrisett, G. & Uustalu, T. (eds) Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP 2013. ACM, pp. 185196.Google Scholar
Abel, A., Pientka, B., Thibodeau, D. & Setzer, A. (2013) Copatterns: Programming infinite structures by observations. In Proceedings of the 40th ACM Symposium on Principles of Programming Languages, POPL 2013, Giacobazzi, R. & Cousot, R. (eds). ACM Press, pp. 2738.Google Scholar
Abel, A., Adelsberger, S. & Setzer, A. (2016) ooAgda. Available at: https://github.com/agda/ooAgda Google Scholar
Abelson, H., Sussman, G. J. & Sussman, J. (1996) Structure and Interpretation of Computer Programs, 2nd ed. MIT Press.Google Scholar
Agda. 2016 With-abstraction. Retrieved November 28, 2016. Available at: http://agda.readthedocs.io/en/latest/language/with-abstraction.html Google Scholar
Agda Wiki. 2011 MAlonzo. Retrieved October 11, 2016. Available at: http://wiki.portal.chalmers.se/agda/pmwiki.php?n=Docs.MAlonzo Google Scholar
Agda Wiki. (2016) The Agda Wiki. Available at: http://wiki.portal.chalmers.se/agda/pmwiki.php Google Scholar
Altenkirch, T. & Danielsson, N. A. (2012) Termination checking in the presence of nested inductive and coinductive types. In Bove, A., Komendantskaya, E. & Niqui, M. (eds), Proceedings of the workshop on Partiality And Recursion in Interactive Theorem Provers, PAR 2010 EPiC Series in Computer Science, vol. 5. EasyChair, pp. 101–106.Google Scholar
Altenkirch, T. & Morris, P. (2009) Indexed containers. In Proceedings of the 24nd IEEE Symposium on Logic in Computer Science, LICS 2009. IEEE Computer Society, pp. 277285.Google Scholar
Amadio, R. M. & Coupet-Grimal, S. (1998) Analysis of a guard condition in type theory (extended abstract) In Nivat, M. (ed), Proceedings of the 1st International Conference on Foundations of Software Science and Computation Structure, FOSSACS'98, Lecture Notes in Computer Science, vol. 1378. Springer, pp. 4862.CrossRefGoogle Scholar
Barthe, G., Frade, M. J., Giménez, E., Pinto, L. & Uustalu, T. (2004) Type-based termination of recursive definitions. Math. Struct. Comput. Sci. 14 (1), 97141.Google Scholar
Barthe, G., Grégoire, B. & Pastawski, F. (2005) Practical inference for type-based termination in a polymorphic setting. In Urzyczyn, P. (ed), Proceedings of the 7th International Conference on Typed Lambda Calculi and Applications, TLCA 2005, Lecture Notes in Computer Science, vol. 3461. Springer, pp. 7185.Google Scholar
Barthe, G., Grégoire, B. & Riba, C. (2008) Type-based termination with sized products. In Kaminski, M. & Martini, S. (eds), Proceedings of the 22nd International Workshop on Computer Science Logic, CSL 2008, 17th Annual Conference of the EACSL, Lecture Notes in Computer Science, vol. 5213. Springer, pp. 493507.Google Scholar
Bauer, A. & Pretnar, M. (2012) Programming with algebraic effects and handlers. arXiv http://arxiv.org/abs/1203.1539.Google Scholar
Bauer, A. & Pretnar, M. (2015) Programming with algebraic effects and handlers. J. Log. Algebr. Methods Program. 84 (1), 108123.Google Scholar
Benke, M. (2007) Alonzo – A compiler for Agda. Talk given at TYPES 2007. Available at: http://www.mimuw.edu.pl/ben/Papers/TYPES07-alonzo.pdf Google Scholar
Blanchette, J. C., Popescu, A. & Traytel, D. (2015) Foundational extensible corecursion: a proof assistant perspective. In Fisher, K. & Reppy, J. H. (eds), Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming, ICFP 2015. ACM, pp. 192204.Google Scholar
Blanqui, F. (2004) A type-based termination criterion for dependently-typed higher-order rewrite systems. In van Oostrom, V. (ed), Rewriting Techniques and Applications, RTA 2004, Aachen, Germany, Lecture Notes in Computer Science, vol. 3091. Springer, pp. 2439.CrossRefGoogle Scholar
Boehm, H.-J. & Steele, G. L. Jr. (eds). (1996) In Proceedings of the 23rd ACM Symposium on Principles of Programming Languages, POPL'96. ACM.Google Scholar
Brady, E. (2014) Resource-dependent algebraic effects. In Proceedings of the 15th International Symposium on Trends in Functional Programming, TFP 2014, Soesterberg, The Netherlands, May 26–28, 2014. Revised Selected Papers, Lecture Notes in Computer Science, Hage, J. & McCarthy, J. (eds), vol. 8843. Springer, pp. 1833.Google Scholar
Coq Community. (2015) The Coq Proof Assistant. Available at: https://coq.inria.fr/.Google Scholar
Coquand, T. (1994) Infinite objects in type theory. In Barendregt, H. & Nipkow, T. (eds), Proceedings of the International Workshop on Types for Proofs and Programs, TYPES '93, Lecture Notes in Computer Sciience, vol. 806. Springer, pp. 6278.CrossRefGoogle Scholar
Dybjer, P. (1994) Inductive families. Formal Asp. Comput. 6 (4), 440465.CrossRefGoogle Scholar
Dybjer, P. & Setzer, A. (2003) Induction-recursion and initial algebras. Ann. Pure Appl. Logic 124, 147.CrossRefGoogle Scholar
Garcia, R., Tanter, É., Wolff, R. & Aldrich, J. (2014) Foundations of typestate-oriented programming. ACM Trans. Program. Lang. Syst. 36 (4), 12:112:44.CrossRefGoogle Scholar
Giménez, E. (1996 December) Un calcul de constructions infinies et son application a la vérification de systèmes communicants (Ph.D. thesis), Ecole Normale Supérieure de Lyon. Thèse d'université.Google Scholar
Giménez, E. (1998) Structural recursive definitions in type theory. In Larsen, K. G., Skyum, S. & Winskel, G. (eds), Proceedings of International Colloquium on Automata, Languages and Programming (ICALP'98), Aalborg, Denmark, Lecture Notes in Computre Science, vol. 1443. Springer, pp. 397408.Google Scholar
Girard, J.-Y. (1972) Interprétation fonctionnelle et élimination des coupures dans l'arithmétique d'ordre supérieur (Thèse de Doctorat d'État). Université de Paris VII.Google Scholar
Gordon, A. D. (ed). (2003) Proceedings of the 6th International Conference on Foundations of Software Science and Computational Structures, FoSSaCS 2003, Lecture Notes in Computer Science, vol. 2620. Springer.Google Scholar
Granström, J. G. (2012) A new paradigm for component-based development. J. Softw. 7 (5), 11361148.CrossRefGoogle Scholar
Granström, J. G. 2016 Intuitionistic Programming Language. Retrieved July 08, 2016. Available at: http://intuitionistic.org/ Google Scholar
Hackage. 2016 Control.Monad.STM. Retrieved February 17, 2016. Available at: https://hackage.haskell.org/package/stm-2.4.4/docs/Control-Monad-STM.html Google Scholar
Hagino, T. (1989) Codatatypes in ML. J. Symb. Logic 8 (6), 629650.Google Scholar
Hancock, P. & Hyvernat, P. (2006) Programming interfaces and basic topology. Ann. Pure Appl. Log. 137, 189239.CrossRefGoogle Scholar
Hancock, P., McBride, C., Ghani, N., Malatesta, L. & Altenkirch, T. (2013) Small induction recursion. In Hasegawa, M. (ed), Typed Lambda Calculi and Applications, Lecture Notes in Computer Science, vol. 7941. Berlin, Heidelberg: Springer, pp. 156172.CrossRefGoogle Scholar
Hancock, P. & Setzer, A. (2000a) Interactive programs in dependent type theory. In Clote, P. & Schwichtenberg, H. (eds), Proceedings of the 14th International Workshop on Computer Science Logic, CSL 2000, 9th Annual Conference of the EACSL, Lecture Notes in Computer Science, vol. 1862. Springer, pp. 317331.Google Scholar
Hancock, P. & Setzer, A. (2000b) Specifying interactions with dependent types. In Proceedings of the Workshop on Subtyping and Dependent Types in Programming, Portugal, 7 July 2000. Electronic proceedings, available at: http://www-sop.inria.fr/oasis/DTP00/Proceedings/proceedings.html Google Scholar
Hancock, P. & Setzer, A. (2005) Interactive programs and weakly final coalgebras in dependent type theory. In Crosilla, L. & Schuster, P. (eds), From Sets and Types to Topology and Analysis. Towards Practicable Foundations for Constructive Mathematics, Oxford Logic Guides. Oxford: Oxford Univ. Press.Google Scholar
Harris, T., Marlow, S., Peyton Jones, S. L. & Herlihy, M. (2008) Composable memory transactions. Commun. ACM 51 (8), 91100.CrossRefGoogle Scholar
Haskell, W. 2016 wxHaskell quick start. Retrieved February 09, 2016. Available at: https://wiki.haskell.org/WxHaskell/Quick_start Google Scholar
Hirschfeld, R., Costanza, P. & Nierstrasz, O. (2008) Context-oriented programming. J. Obj. Tech. 7 (3), 125151.CrossRefGoogle Scholar
Hudak, P. 2016 SOE library. Retrieved February 12, 2016. Available at: http://www.cs.yale.edu/homes/hudak/SOE/software1.htm Google Scholar
Hughes, J., Pareto, L. & Sabry, A. (1996) Proving the correctness of reactive systems using sized types. In Boehm, H.-J. & Steele, G. L. Jr. (eds). (1996) In Proceedings of the 23rd ACM Symposium on Principles of Programming Languages, POPL'96. ACM.Google Scholar
Hurkens, A. J. C. (1995) A simplification of Girard's paradox. In Dezani-Ciancaglini, M. & Plotkin, G. D. (eds), Proceedings of the 2nd International Conference on Typed Lambda Calculi and Applications, TLCA '95, Lecture Notes in Computer Science, vol. 902. Springer, pp. 266278.CrossRefGoogle Scholar
Igried, B. & Setzer, A. (2016) Programming with monadic CSP-style processes in dependent type theory. In Proceedings of the 1st International Workshop on Type-Driven Development, TyDe 2016, New York: ACM, pp. 2838.CrossRefGoogle Scholar
Jeffrey, A. (2013) Dependently typed web client applications–-FRP in Agda in HTML5. In Sagonas, K. F. (ed), Proceedings of the 15th International Symposium on Practical Aspects of Declarative Languages, PADL 2013, Lecture Notes in Computer Science, vol. 7752. Springer, pp. 228243.Google Scholar
Leijen, D. (2004) wxHaskell: A portable and concise GUI library for Haskell. In Nilsson, H. (ed).Proceedings of the ACM SIGPLAN Workshop on Haskell, Haskell 2004 ACM Press, pp. 5768.CrossRefGoogle Scholar
Leijen, D. 2015 (Commit f2f5b5a 23 September) wxAsteroids. Available at: https://github.com/wxHaskell/wxAsteroids Google Scholar
Lochbihler, A. & Züst, M. (2014) Programming TLS in Isabelle/HOL. In Proceedings of Isabelle Workshop, Associated with ITP 2014. Available from https://www.ethz.ch/content/dam/ethz/special-interest/infk/inst-infsec/information-security-group-dam/people/andreloc/lochbihler14iw.pdf.Google Scholar
Martin-Löf, P. (1984) Intuitionistic Type Theory. Naples: Bibliopolis.Google Scholar
Matthes, R. (2002) Tarski's fixed-point theorem and lambda calculi with monotone inductive types. Synthese 133 (1–2), 107129.CrossRefGoogle Scholar
McBride, C. & McKinna, J. (2004) The view from the left. J. Funct. Program. 14 (1), 69111.CrossRefGoogle Scholar
Mendler, N. P., Panangaden, P. & Constable, R. L. (1986) Infinite objects in type theory. In Proceedings of the 1st IEEE Symposium on Logic in Computer Science, LICS '86. IEEE Computer Society, pp. 249255.Google Scholar
Moggi, E. (1991) Notions of computation and monads. Inf. Comput. 93 (1), 5592.CrossRefGoogle Scholar
Nordström, B., Petersson, K. & Smith, J. M. (2001) Martin-löf's type theory. In Abramsky, S., Gabbay, D. M. & Maibaum, T. S. E. (eds), Handbook of Logic in Computer Science: Logic and Algebraic Methods, vol. 5. USA: Oxford Univ. Press.Google Scholar
Nordvall Forsberg, F. & Setzer, A. (2010) Inductive-inductive definitions. In Dawar, A. & Veith, H. (eds), Proceedings if CSL 2010 Lecture Notes in Computer Science, vol. 6247. Heidelberg: Springer, pp. 454468.Google Scholar
Norell, U. (2007 September) Towards a Practical Programming Language Based on Dependent Type Theory (Ph.D. thesis). Göteborg, Sweden: Dept. of Comput. Sci. and Eng., Chalmers Univ.Google Scholar
Petersson, K. & Synek, D. (1989) A set constructor for inductive sets in Martin-Löf's Type Theory. In Pitt, D. H., Rydeheard, D. E., Dybjer, P., Pitts, A. M. & Poigné, A. (eds), Category Theory and Computer Science, Lecture Notes in Computer Science, vol. 389. London: Springer-Verlag, pp. 128140.CrossRefGoogle Scholar
Peyton, Jones, S. L., Gordon, A. D. & Finne, S. (1996) Concurrent Haskell. In Boehm, H.-J. & Steele, G. L. Jr. (eds). In Proceedings of the 23rd ACM Symposium on Principles of Programming Languages, POPL'96. ACM.Google Scholar
Sacchini, J. L. (2013) Type-based productivity of stream definitions in the calculus of constructions. In Proceedings of 28th IEEE Symposium on Logic in Computer Science, LICS '13. IEEE Computer Society, pp. 233–242.CrossRefGoogle Scholar
Sculthorpe, N. & Nilsson, H. (2009) Safe functional reactive programming through dependent types. In Hutton, G. & Tolmach, A. P. (eds), Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming, ICFP 2009. ACM, pp. 23–34.CrossRefGoogle Scholar
Setzer, A. (2006) Object-oriented programming in dependent type theory. In Nilsson, H. (ed), Revised Selected Papers from the 7th Symposium on Trends in Functional Programming, TFP 2006, vol. 7. Intellect Books, pp. 91108.Google Scholar
Setzer, A. (2012) Coalgebras as types determined by their elimination rules. In Dybjer, P., Lindström, S., Palmgren, E. & Sundholm, G. (eds), Epistemology versus Ontology Logic, Epistemology, and the Unity of Science, vol. 27. Springer Netherlands, pp. 351369. doi: 10.1007/978-94-007-4435-6_16.CrossRefGoogle Scholar
Setzer, A. (2016) How to reason coinductively informally. In Kahle, R., Strahm, T. & Studer, T. (eds), Advances in Proof Theory. Springer, pp. 377408.CrossRefGoogle Scholar
Setzer, A. & Hancock, P. (2004) Interactive programs and weakly final coalgebras in dependent type theory (extended version) In Altenkirch, T., Hofmann, M. & Hughes, J. (eds), Dependently Typed Programming 2004, Dagstuhl Seminar Proceedingss, vol. 04381. Schloss Dagstuhl, Germany: IBFI.Google Scholar
Sprenger, C. & Dam, M. (2003) On the structure of inductive reasoning: Circular and tree-shaped proofs in the μ-calculus. In Gordon, A. D. (ed), Proceedings of the 6th International Conference on Foundations of Software Science and Computational Structures, FOSSACS 2003, Lecture Notes in Computer Science, vol. 2620. Springer.Google Scholar
Strom, R. E. & Yemini, S. (1986) Typestate: A programming language concept for enhancing software reliability. IEEE Trans. Softw. Eng., 157–171.CrossRefGoogle Scholar
Stump, A. (2016) Verified Functional Programming in Agda. Morgan & Claypool.CrossRefGoogle Scholar
Wegner, P. (1987) Dimensions of object-based language design. In Proceedings of the Conference on Object-Oriented Programming Systems, Languages, and Applications, OOPSLA '87, SIGPLAN Not. 22 (12), 168–182.CrossRefGoogle Scholar
Submit a response

Discussions

No Discussions have been published for this article.