Strict Typed Functional Programming in OCaml Part I in CUGS course Functional and Logic Programming Linköping University, May 3-5, 2010 David Broman Department of Computer and Information Science Linköping University, Sweden david.broman@liu.se 2 Agenda David Broman davbr@ida.liu.se Part I Intro to Functional Programming Part II Course Information Part III Learning by Doing Part I Intro to Functional Programming Part II Course Information Part III Learning by doing 3 David Broman davbr@ida.liu.se Part I Intro to Functional Programming Part I Intro to Functional Programming Part II Course Information Part III Learning by doing 4 What is functional programming? David Broman davbr@ida.liu.se Procedural languages C Pascal Supports and encourages Object-oriented languages Java C++ SML Smalltalk LISP Functional languages Scheme Haskell Imperative Programming Basic method of computation is changing store values, e.g., via assignments F# OCaml Supports and encourages Functional Programming A style of programming where the basic method of computation is the application of functions to arguments. (Hutton, 2007) Part I Intro to Functional Programming Part II Course Information Part III Learning by doing 5 What is functional programming? Example: Imperative Style (C) Functional Style (OCaml) - Variables bound only once - Recursion - Destructive assignments - Loops Part I Intro to Functional Programming Part II Course Information Part III Learning by doing David Broman davbr@ida.liu.se 6 What kinds of FP languages exist? Static type checking OCaml SML Clean Haskell Strict (Eager) OCaml SML Lisp Pure Haskell Part I Intro to Functional Programming vs. Dynamic (type) checking Scheme Part II Course Information (Python) Lisp Non-strict (Lazy) vs. Haskell Clean Non-pure vs. Clean David Broman davbr@ida.liu.se OCaml Part III Learning by doing SML Lisp Scheme 7 Is FP something new? 1930s David Broman davbr@ida.liu.se - the lambda calculus by Alonzo Church 1940s - Lisp (“LISt Processor”) by John McCarthy. FP with assignments 1950s - ISWIM (“If you See What I Mean”) by Peter Landin. First pure FP 1960s 1970s 1980s - FP (“Functional Programming”) by John Backus. - ML (“Meta-Language”) by Robin Milner and others. Polymorphic types and type inference - Miranda by David Turner. Lazy function language. - Haskell, international committee formed (1987) - Caml (1985-), INRIA 1990s 2000s Part I Intro to Functional Programming - OCaml by Xavier Leroy and others. - Haskell 98 report (1999), Revised report (2003) - F# by Microsoft Part II Course Information Part III Learning by doing 8 David Broman davbr@ida.liu.se Part II Course Information Part I Intro to Functional Programming Part II Course Information Part III Learning by doing 9 Contents of FP Course David Broman davbr@ida.liu.se Part I (Strict FP in OCaml) ! Fundamentals of typed functional programming (Lists, patternmatching, higher-order functions etc.) ! Fundamentals of untyped lambda calculus theory ! Objective: to become an “OCaml programmer” Part II (Lazy FP in Haskell) ! Advanced concepts related (but not limited to) lazy FP. ! E.g., lazy evaluation, pure functional data structures, notation of effectful programming (Monads), Type classes etc. ! Learn to program in Haskell Part III (Mini-project) ! Individual project (approx. 1 weeks of full time work) ! Haskell or OCaml ! Preferably related to your research or other interests Part I Intro to Functional Programming Part II Course Information Part III Learning by doing 10 Schedule and Teachers David Broman davbr@ida.liu.se Part I (Strict FP in OCaml) ! Mon , May 3, 10.15 - 17.00 ! Tue, May 4, 09.15 - 17.00 ! Wed, May 5, 09.15 - 16.00 Teacher Part I ! David Broman ! david.broman@liu.se Part II (Lazy FP in Haskell) ! Mon, May 17, 10.15 - 17.00 ! Tue, May 18, 09.15 - 17.00 ! Wed, May 19, 09.15 - 16.00 Teacher Part II ! Henrik Nilsson ! nhn@cs.nott.ac.uk Part III (Mini-project) ! Thy, June 10, 10.15 - 17.00 ! Fri, June 11, 09.15 - 16.00 Examiner ! Peter Fritzson ! petfr@ida.liu.se Part I Intro to Functional Programming Part II Course Information Part III Learning by doing 11 Examination and Deadlines David Broman davbr@ida.liu.se Examination ! A set of programming exercises in OCaml. ! A set of programming exercises in Haskell. ! An individual software project. Source code + 1 page extended abstract. ! Oral presentation of the individual project. ! Being a discussion leader for another project during the presentation. Submission ! One archive file (zip or tar.gz). ! A README file describing structure and contents. ! All documents in PDF. ! Send to all teachers and the examiner (David, Henrik, and Peter). ! Send project files to your discussion leader. Deadline ! June 7, 8 am ! Abstract will be made public on website June 7 Part I Intro to Functional Programming Part II Course Information Part III Learning by doing 12 David Broman davbr@ida.liu.se Part III Learning by Doing Part I Intro to Functional Programming Part II Course Information Part III Learning by doing 13 Part I - Learning by doing David Broman davbr@ida.liu.se “Doing” - active learning ! Reading ! Example ! Task “Discussion Session” Let’s do it! “Concepts and Insights” Part I Intro to Functional Programming Part II Course Information Part III Learning by doing