DE TTK 1949 The Appearance of Multiparadigm Programming Languages in the Teaching of Arti(cid:28)cial Intelligence Egyetemi doktori (Ph.D.) ØrtekezØs PÆnovics JÆnos Dr. Fazekas GÆbor TØmavezetfi: Debreceni Egyetem TermØszettudomÆnyi Doktori TanÆcs Matematika- Øs SzÆm(cid:237)tÆstudomÆnyok Doktori Iskola Debrecen, 2013 DE TTK 1949 The Appearance of Multiparadigm Programming Languages in the Teaching of Arti(cid:28)cial Intelligence Egyetemi doktori (Ph.D.) ØrtekezØs PÆnovics JÆnos Dr. Fazekas GÆbor TØmavezetfi: Debreceni Egyetem TermØszettudomÆnyi Doktori TanÆcs Matematika- Øs SzÆm(cid:237)tÆstudomÆnyok Doktori Iskola Debrecen, 2013 Ezen ØrtekezØst a Debreceni Egyetem TermØszettudomÆnyi Dokto- ri TanÆcs Matematika- Øs SzÆm(cid:237)tÆstudomÆnyok Doktori Iskola Szak- m(cid:243)dszertan programja keretØben kØsz(cid:237)tettem a Debreceni Egyetem termØszettudomÆnyi doktori (Ph.D.) fokozatÆnak elnyerØse cØljÆb(cid:243)l. Debrecen, 2013. Æprilis 23. PÆnovics JÆnos doktorjel(cid:246)lt Tanœs(cid:237)tom,hogyPÆnovicsJÆnosdoktorjel(cid:246)lt1999(cid:21)2002k(cid:246)z(cid:246)ttafent megnevezett Doktori Iskola Informatika programjÆnak keretØben irÆ- ny(cid:237)tÆsommal vØgezte munkÆjÆt. Az ØrtekezØsben foglalt eredmØnyek- hezajel(cid:246)lt(cid:246)nÆll(cid:243)alkot(cid:243)tevØkenysØgØvelmeghatÆroz(cid:243)anhozzÆjÆrult. Az ØrtekezØs elfogadÆsÆt javasolom. Debrecen, 2013. Æprilis 23. Dr. Fazekas GÆbor tØmavezetfi The Appearance of Multiparadigm Programming Languages in the Teaching of Arti(cid:28)cial Intelligence (cid:201)rtekezØs a doktori (Ph.D.) fokozat megszerzØse ØrdekØben a matematika- Øs szÆm(cid:237)tÆstudomÆnyok tudomÆnyÆgban ˝rta: PÆnovics JÆnos okleveles programtervezfi matematikus KØsz(cid:252)lt a Debreceni Egyetem Matematika- Øs SzÆm(cid:237)tÆstudomÆnyok Doktori IskolÆja (Szakm(cid:243)dszertan programja) keretØben TØmavezetfi: Dr. Fazekas GÆbor A doktori szigorlati bizottsÆg: eln(cid:246)k: Dr. PÆles Zsolt ...................... tagok: Dr. Fekete IstvÆn ...................... Dr. VÆrterØsz Magda ...................... A doktori szigorlat idfipontja: 2012. mÆrcius 9. Az ØrtekezØs b(cid:237)rÆl(cid:243)i: Dr. .................. ...................... Dr. .................. ...................... Dr. .................. ...................... A b(cid:237)rÆl(cid:243)bizottsÆg: eln(cid:246)k: Dr. .................. ...................... tagok: Dr. .................. ...................... Dr. .................. ...................... Dr. .................. ...................... Dr. .................. ...................... Az ØrtekezØs vØdØsØnek idfipontja: 2014. ................ ... . Contents Acknowledgments 1 1 Introduction 2 2 Overview of Functional Programming 5 2.1 The Lambda Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.2 Functional Approach in Teaching Arti(cid:28)cial Intelligence . . . . . . . . . . 9 2.2.1 Search Algorithms in Di(cid:27)erent Programming Languages . . . . . 13 2.3 Multiparadigm Languages and F# . . . . . . . . . . . . . . . . . . . . . 14 3 Some Implementations of Search Algorithms for Single-Agent Prob- lems 16 3.1 A Class Hierarchy for Search Algorithms . . . . . . . . . . . . . . . . . . 17 3.2 Various Implementations of Search Algorithms . . . . . . . . . . . . . . 20 3.2.1 The C# Implementation . . . . . . . . . . . . . . . . . . . . . . . 20 3.2.2 The First F# Implementation. . . . . . . . . . . . . . . . . . . . 32 3.2.3 The Second F# Implementation . . . . . . . . . . . . . . . . . . 41 3.2.4 The Third F# Implementation . . . . . . . . . . . . . . . . . . . 46 3.2.5 Comparing the Four Implementations . . . . . . . . . . . . . . . 55 3.3 Implementing Speci(cid:28)c Problems. . . . . . . . . . . . . . . . . . . . . . . 58 3.3.1 Towers of Hanoi . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 3.3.2 Funfair Puzzle . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 4 Some Implementations of Search Algorithms on Game Trees 94 4.1 A Class Hierarchy for Search Algorithms . . . . . . . . . . . . . . . . . . 95 4.2 Various Implementations of Search Algorithms . . . . . . . . . . . . . . 98 4.2.1 The C# Implementation . . . . . . . . . . . . . . . . . . . . . . . 98 4.2.2 The First F# Implementation. . . . . . . . . . . . . . . . . . . . 106 4.2.3 The Second F# Implementation . . . . . . . . . . . . . . . . . . 112 4.2.4 Comparing the Three Implementations. . . . . . . . . . . . . . . 118 4.3 Implementing Speci(cid:28)c Problems. . . . . . . . . . . . . . . . . . . . . . . 119 5 A New Methodology for Teaching Computer Science 130 5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 5.2 Current Program Requirements . . . . . . . . . . . . . . . . . . . . . . . 132 5.3 Some Possible Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 5.3.1 Project #1: Creating a Reversi Application . . . . . . . . . . . . 134 5.3.2 Project #2: Creating a Library Information System . . . . . . . 140 5.3.3 Further Subjects and Projects. . . . . . . . . . . . . . . . . . . . 141 5.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 6 Supporting Programming Contests with the ProgCont Application 143 6.1 About Programming Contests . . . . . . . . . . . . . . . . . . . . . . . . 144 6.2 The Architecture and Operation of ProgCont . . . . . . . . . . . . . . . 146 6.3 OurExperiencewiththeApplicationandPossibilitiesforFutureDevel- opment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 7 Summary 156 8. (cid:214)sszefoglalÆs 158 8.1. (cid:218)j m(cid:243)dszertan az informatikaoktatÆsban . . . . . . . . . . . . . . . . . . 159 8.2. MultiparadigmÆsprogramozÆsinyelvekhasznÆlataamestersØgesintelli- gencia oktatÆsÆban . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 8.3. Programoz(cid:243) versenyek lebonyol(cid:237)tÆsa a ProgCont alkalmazÆssal . . . . . 164 Bibliography 170 List of Publications 171 Acknowledgments First of all, I would like to thank my supervisor, Fazekas GÆbor, for his guidance and encouragement. I am also very grateful for the invaluable help and support given by VÆrterØsz Magda, who acted like a mentor throughout my whole career. Many thanks to my colleague and friend K(cid:243)sa MÆrk for all the useful advice he has given me, as wellasSterbinszkyN(cid:243)raforthebaseideaofthisthesis. Finally, Ithankmyfamilyfor their support and long-su(cid:27)ering patience. The work is supported by the T`MOP- 4.2.2/B-10/1-2010-0024 project. The project is co-(cid:28)nanced by the Eu- ropean Union and the European Social Fund. CHAPTER 1 Introduction Until recently, programming was about using pure, single-paradigm techniques. How- ever, nowadays programming languages tend to converge to one another, i.e., features of one paradigm are appearing in languages based on another paradigm [23, 24]. This process can be observed primarily in the area of imperative, object-oriented, and func- tional programming languages. For example, C# or D are based on the imperative C language, extended with object-oriented and functional language elements. Another example is CLOS, which is a functional language based on Lisp, with added object- oriented features. Such languages are called multiparadigm programming languages. The advantage of these languages is that the programmer may select the paradigm best suited for solving a particular problem. We may even choose to create di(cid:27)erent parts of the same program using techniques from di(cid:27)erent programming paradigms. If a small part of a large application requires high e(cid:30)ciency, imperative code is used, reusable types are created in an object-oriented way, while in some domains of com- putation, we choose the functional approach because solutions to problems in these domains can be expressed in a more succinct way compared to using imperative code. I believe that multiparadigm languages can be a great help in the education of computer science. Instructors may show di(cid:27)erent versions of the same algorithm de- pending on the paradigm used to implement it, and later students may decide which paradigm to choose in a homework assignment, an exam, or at work, depending on the problem speci(cid:28)cation and the student’s programming experience. Of course, we don’tnecessarilyneedtousemultiparadigmlanguagesforthispurpose,wecanalsouse multiple single-paradigm languages, but this way, we don’t have to teach and students don’t have to learn yet another language just for coding a particular algorithm. Duringmyresearch,IexaminedthepossibilityofusingF#asanewmultiparadigm programming language for coding di(cid:27)erent algorithms in the area of arti(cid:28)cial intelli- gence (AI). I chose this area for three main reasons. First, I used to be an instructor of the seminars of the Introduction to Arti(cid:28)cial Intelligence course at the University of Debrecen [28]. Second, AI and search algorithms, in particular, seemed to be a (cid:28)eld of computation where we can make use of functional programming because some sub- stantial parts of these algorithms (like, for example, checking operator preconditions) are essentially functional. And third, I had a couple of imperative and object-oriented
Description: