Functional Programming
Mayer Goldberg \ Ben-Gurion University March 16, 2019
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 1 / 12
Functional Programming March 16, 2019 Functional Programming March - - PowerPoint PPT Presentation
Functional Programming March 16, 2019 Functional Programming March 16, 2019 1 / 12 Mayer Goldberg \ Ben-Gurion University Mayer Goldberg \ Ben-Gurion University Road Map Functional Programming March 16, 2019 2 / 12 Introduction to
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 1 / 12
▶ Bases ▶ Fixed-Point Theory ▶ Functions as Data ▶ Streams ▶ Maps & Folds ▶ CPS & Threading Code ▶ Monads ▶ Possibly additional topics, depending on time
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 2 / 12
▶ We implemented the ordered pair ⟨A, B⟩ as λx.(x A B)
▶ We implemented linked lists as nested, ordered pairs, but unless
▶ We implemented numerals as λsz.(s · · · (s z) · · · )
▶ What we are lacking is run-time type information (RTTI)
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 3 / 12
▶ Our goal is to implement RTTI, and thus enabling us to write
▶ One trivial way to implement RTTI is known in set-theory &
▶ We can pair every object with an encoding of its type ▶ Let c0 represent Church numerals ▶ Let c1 represent Booleans ▶ Let c2 represent pairs
▶ Implement a new set of functions on these listed datatypes, so
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 4 / 12
▶ Advantages of this approach
▶ Simplicity & ease
▶ Disadvantages of this approach
▶ Adds the “noise” of constantly having to test the RTTI:
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 5 / 12
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 6 / 12
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 7 / 12
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 8 / 12
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 9 / 12
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 10 / 12
▶ Advantages of this approach
▶ No “noise” in the form of testing RTTI
▶ Effjcient
▶ Disadvantages of this approach
▶ Cumbersome to add new types ▶ Everything is a procedure
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 11 / 12
▶ There is more than one way to implement RTTI ▶ RTTI & Refmective operations can be made clean & effjcient ▶ Abstraction wins the day!
Mayer Goldberg \ Ben-Gurion University Functional Programming March 16, 2019 12 / 12