Skip to main content
×
Home
    • Aa
    • Aa

Interactive programming in Agda – Objects and graphical user interfaces

  • ANDREAS ABEL (a1), STEPHAN ADELSBERGER (a2) and ANTON SETZER (a3)
Abstract
Abstract

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.

Copyright
References
Hide All
AbadiM. & CardelliL. (eds). (1996) A Theory of Objects, Monographs in Computer Science. Springer.
AbbottM., AltenkirchT. & GhaniN. (2003) Categories of containers. In GordonA. 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.
AbelA. (2007) Mixed inductive/coinductive types and strong normalization. In, ShaoZ. (ed), Proceedings of the 5th Asian Symposium on Programming Languages and Systems, APLAS 2007, Lecture Notes in Computer Science, vol. 4807. Springer, pp. 286301.
AbelA. (2008) Semi-continuous sized types and termination. Log. Meth. Comput. Sci. 4 (2:3), 133 (CSL'06 special issue).
AbelA. (2010) MiniAgda: Integrating sized and dependent types. In BoveA., KomendantskayaE. & NiquiM. (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.
AbelA. (2012) Type-based termination, inflationary fixed-points, and mixed inductive-coinductive types. In MillerD. & ÉsikZ. (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.
AbelA. & AltenkirchT. (2002) A predicative analysis of structural recursion. J. Func. Program. 12 (1), 141.
AbelA. & PientkaB. (2013) Wellfounded recursion with copatterns: A unified approach to termination and productivity. In MorrisettG. & UustaluT. (eds) Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP 2013. ACM, pp. 185196.
AbelA., PientkaB., ThibodeauD. & SetzerA. (2013) Copatterns: Programming infinite structures by observations. In Proceedings of the 40th ACM Symposium on Principles of Programming Languages, POPL 2013, GiacobazziR. & CousotR. (eds). ACM Press, pp. 2738.
AbelA., AdelsbergerS. & SetzerA. (2016) ooAgda. Available at: https://github.com/agda/ooAgda
AbelsonH., SussmanG. J. & SussmanJ. (1996) Structure and Interpretation of Computer Programs, 2nd ed. MIT Press.
Agda. 2016 With-abstraction. Retrieved November 28, 2016. Available at: http://agda.readthedocs.io/en/latest/language/with-abstraction.html
Agda Wiki. 2011 MAlonzo. Retrieved October 11, 2016. Available at: http://wiki.portal.chalmers.se/agda/pmwiki.php?n=Docs.MAlonzo
Agda Wiki. (2016) The Agda Wiki. Available at: http://wiki.portal.chalmers.se/agda/pmwiki.php
AltenkirchT. & DanielssonN. A. (2012) Termination checking in the presence of nested inductive and coinductive types. In BoveA., KomendantskayaE. & NiquiM. (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.
AltenkirchT. & MorrisP. (2009) Indexed containers. In Proceedings of the 24nd IEEE Symposium on Logic in Computer Science, LICS 2009. IEEE Computer Society, pp. 277285.
AmadioR. M. & Coupet-GrimalS. (1998) Analysis of a guard condition in type theory (extended abstract) In NivatM. (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.
BartheG., FradeM. J., GiménezE., PintoL. & UustaluT. (2004) Type-based termination of recursive definitions. Math. Struct. Comput. Sci. 14 (1), 97141.
BartheG., GrégoireB. & PastawskiF. (2005) Practical inference for type-based termination in a polymorphic setting. In UrzyczynP. (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.
BartheG., GrégoireB. & RibaC. (2008) Type-based termination with sized products. In KaminskiM. & MartiniS. (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.
BauerA. & PretnarM. (2012) Programming with algebraic effects and handlers. arXiv http://arxiv.org/abs/1203.1539.
BauerA. & PretnarM. (2015) Programming with algebraic effects and handlers. J. Log. Algebr. Methods Program. 84 (1), 108123.
BenkeM. (2007) Alonzo – A compiler for Agda. Talk given at TYPES 2007. Available at: http://www.mimuw.edu.pl/ben/Papers/TYPES07-alonzo.pdf
BlanchetteJ. C., PopescuA. & TraytelD. (2015) Foundational extensible corecursion: a proof assistant perspective. In FisherK. & ReppyJ. H. (eds), Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming, ICFP 2015. ACM, pp. 192204.
BlanquiF. (2004) A type-based termination criterion for dependently-typed higher-order rewrite systems. In van OostromV. (ed), Rewriting Techniques and Applications, RTA 2004, Aachen, Germany, Lecture Notes in Computer Science, vol. 3091. Springer, pp. 2439.
BoehmH.-J. & SteeleG. L.Jr. (eds). (1996) In Proceedings of the 23rd ACM Symposium on Principles of Programming Languages, POPL'96. ACM.
BradyE. (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, HageJ. & McCarthyJ. (eds), vol. 8843. Springer, pp. 1833.
Coq Community. (2015) The Coq Proof Assistant. Available at: https://coq.inria.fr/.
CoquandT. (1994) Infinite objects in type theory. In BarendregtH. & NipkowT. (eds), Proceedings of the International Workshop on Types for Proofs and Programs, TYPES '93, Lecture Notes in Computer Sciience, vol. 806. Springer, pp. 6278.
DybjerP. (1994) Inductive families. Formal Asp. Comput. 6 (4), 440465.
DybjerP. & SetzerA. (2003) Induction-recursion and initial algebras. Ann. Pure Appl. Logic 124, 147.
GarciaR., TanterÉ., WolffR. & AldrichJ. (2014) Foundations of typestate-oriented programming. ACM Trans. Program. Lang. Syst. 36 (4), 12:112:44.
GiménezE. (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é.
GiménezE. (1998) Structural recursive definitions in type theory. In LarsenK. G., SkyumS. & WinskelG. (eds), Proceedings of International Colloquium on Automata, Languages and Programming (ICALP'98), Aalborg, Denmark, Lecture Notes in Computre Science, vol. 1443. Springer, pp. 397408.
GirardJ.-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.
GordonA. 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.
GranströmJ. G. (2012) A new paradigm for component-based development. J. Softw. 7 (5), 11361148.
GranströmJ. G. 2016 Intuitionistic Programming Language. Retrieved July 08, 2016. Available at: http://intuitionistic.org/
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
HaginoT. (1989) Codatatypes in ML. J. Symb. Logic 8 (6), 629650.
HancockP. & HyvernatP. (2006) Programming interfaces and basic topology. Ann. Pure Appl. Log. 137, 189239.
HancockP., McBrideC., GhaniN., MalatestaL. & AltenkirchT. (2013) Small induction recursion. In HasegawaM. (ed), Typed Lambda Calculi and Applications, Lecture Notes in Computer Science, vol. 7941. Berlin, Heidelberg: Springer, pp. 156172.
HancockP. & SetzerA. (2000a) Interactive programs in dependent type theory. In CloteP. & SchwichtenbergH. (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.
HancockP. & SetzerA. (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
HancockP. & SetzerA. (2005) Interactive programs and weakly final coalgebras in dependent type theory. In CrosillaL. & SchusterP. (eds), From Sets and Types to Topology and Analysis. Towards Practicable Foundations for Constructive Mathematics, Oxford Logic Guides. Oxford: Oxford Univ. Press.
HarrisT., MarlowS., Peyton JonesS. L. & HerlihyM. (2008) Composable memory transactions. Commun. ACM 51 (8), 91100.
HaskellW. 2016 wxHaskell quick start. Retrieved February 09, 2016. Available at: https://wiki.haskell.org/WxHaskell/Quick_start
HirschfeldR., CostanzaP. & NierstraszO. (2008) Context-oriented programming. J. Obj. Tech. 7 (3), 125151.
HudakP. 2016 SOE library. Retrieved February 12, 2016. Available at: http://www.cs.yale.edu/homes/hudak/SOE/software1.htm
HughesJ., ParetoL. & SabryA. (1996) Proving the correctness of reactive systems using sized types. In BoehmH.-J. & SteeleG. L.Jr. (eds). (1996) In Proceedings of the 23rd ACM Symposium on Principles of Programming Languages, POPL'96. ACM.
HurkensA. J. C. (1995) A simplification of Girard's paradox. In Dezani-CiancagliniM. & PlotkinG. 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.
IgriedB. & SetzerA. (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.
JeffreyA. (2013) Dependently typed web client applications–-FRP in Agda in HTML5. In SagonasK. 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.
LeijenD. (2004) wxHaskell: A portable and concise GUI library for Haskell. In NilssonH. (ed).Proceedings of the ACM SIGPLAN Workshop on Haskell, Haskell 2004 ACM Press, pp. 5768.
LeijenD. 2015 (Commit f2f5b5a 23 September) wxAsteroids. Available at: https://github.com/wxHaskell/wxAsteroids
LochbihlerA. & ZüstM. (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.
Martin-LöfP. (1984) Intuitionistic Type Theory. Naples: Bibliopolis.
MatthesR. (2002) Tarski's fixed-point theorem and lambda calculi with monotone inductive types. Synthese 133 (1–2), 107129.
McBrideC. & McKinnaJ. (2004) The view from the left. J. Funct. Program. 14 (1), 69111.
MendlerN. P., PanangadenP. & ConstableR. 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.
MoggiE. (1991) Notions of computation and monads. Inf. Comput. 93 (1), 5592.
NordströmB., PeterssonK. & SmithJ. M. (2001) Martin-löf's type theory. In AbramskyS., GabbayD. M. & MaibaumT. S. E. (eds), Handbook of Logic in Computer Science: Logic and Algebraic Methods, vol. 5. USA: Oxford Univ. Press.
Nordvall ForsbergF. & SetzerA. (2010) Inductive-inductive definitions. In DawarA. & VeithH. (eds), Proceedings if CSL 2010 Lecture Notes in Computer Science, vol. 6247. Heidelberg: Springer, pp. 454468.
NorellU. (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.
PeterssonK. & SynekD. (1989) A set constructor for inductive sets in Martin-Löf's Type Theory. In PittD. H., RydeheardD. E., DybjerP., PittsA. M. & PoignéA. (eds), Category Theory and Computer Science, Lecture Notes in Computer Science, vol. 389. London: Springer-Verlag, pp. 128140.
PeytonJones, S. L., GordonA. D. & FinneS. (1996) Concurrent Haskell. In BoehmH.-J. & SteeleG. L.Jr. (eds). In Proceedings of the 23rd ACM Symposium on Principles of Programming Languages, POPL'96. ACM.
SacchiniJ. 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.
SculthorpeN. & NilssonH. (2009) Safe functional reactive programming through dependent types. In HuttonG. & TolmachA. P. (eds), Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming, ICFP 2009. ACM, pp. 23–34.
SetzerA. (2006) Object-oriented programming in dependent type theory. In NilssonH. (ed), Revised Selected Papers from the 7th Symposium on Trends in Functional Programming, TFP 2006, vol. 7. Intellect Books, pp. 91108.
SetzerA. (2012) Coalgebras as types determined by their elimination rules. In DybjerP., LindströmS., PalmgrenE. & SundholmG. (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.
SetzerA. (2016) How to reason coinductively informally. In KahleR., StrahmT. & StuderT. (eds), Advances in Proof Theory. Springer, pp. 377408.
SetzerA. & HancockP. (2004) Interactive programs and weakly final coalgebras in dependent type theory (extended version) In AltenkirchT., HofmannM. & HughesJ. (eds), Dependently Typed Programming 2004, Dagstuhl Seminar Proceedingss, vol. 04381. Schloss Dagstuhl, Germany: IBFI.
SprengerC. & DamM. (2003) On the structure of inductive reasoning: Circular and tree-shaped proofs in the μ-calculus. In GordonA. 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.
StromR. E. & YeminiS. (1986) Typestate: A programming language concept for enhancing software reliability. IEEE Trans. Softw. Eng., 157–171.
StumpA. (2016) Verified Functional Programming in Agda. Morgan & Claypool.
WegnerP. (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.
Recommend this journal

Email your librarian or administrator to recommend adding this journal to your organisation's collection.

Journal of Functional Programming
  • ISSN: 0956-7968
  • EISSN: 1469-7653
  • URL: /core/journals/journal-of-functional-programming
Please enter your name
Please enter a valid email address
Who would you like to send this to? *
×

Metrics

Full text views

Total number of HTML views: 0
Total number of PDF views: 56 *
Loading metrics...

Abstract views

Total abstract views: 407 *
Loading metrics...

* Views captured on Cambridge Core between 6th February 2017 - 21st October 2017. This data will be updated every 24 hours.