Presented By Andrew Butt

Similar documents
Refactoring to Functional. Hadi Hariri

Chapter 11 :: Functional Languages

Functional Programming and Haskell

Functional Programming

Programming Language Pragmatics

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

Functional Programming. Big Picture. Design of Programming Languages

3. Functional Programming. Oscar Nierstrasz

Functional Programming

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

Functional Languages. Hwansoo Han

4/19/2018. Chapter 11 :: Functional Languages

Programming Paradigms in Python

Functional Programming Lecture 13: FP in the Real World

Programming with Math and Logic

Weeks 6&7: Procedures and Parameter Passing

Concepts of Programming Languages

Functional Programming Lecture 1: Introduction

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

CMSC330. Objects, Functional Programming, and lambda calculus

Functional Programming

Functional Programming Languages (FPL)

Functional Programming in Java. CSE 219 Department of Computer Science, Stony Brook University

Stop coding Pascal. Saturday, April 6, 13

INF 102 CONCEPTS OF PROG. LANGS FUNCTIONAL COMPOSITION. Instructors: James Jones Copyright Instructors.

What are the characteristics of Object Oriented programming language?

Introduction to Concepts in Functional Programming. CS16: Introduction to Data Structures & Algorithms Spring 2017

Introduction to Functional Programming and Haskell. Aden Seaman

Topic 1: Introduction

G Programming Languages - Fall 2012

More Lambda Calculus and Intro to Type Systems

Class Structure. Prerequisites

CS558 Programming Languages

Functional Languages and Higher-Order Functions

Introduction to the Lambda Calculus

CS 314 Principles of Programming Languages

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations

CS 11 Haskell track: lecture 1

Recursion. Tjark Weber. Functional Programming 1. Based on notes by Sven-Olof Nyström. Tjark Weber (UU) Recursion 1 / 37

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

Functional Programming Principles in Scala. Martin Odersky

LECTURE 16. Functional Programming

Programming II. Modularity 2017/18

Introduction. chapter Functions

CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers

History. Functional Programming. Based on Prof. Gotshalks notes on functionals. FP form. Meaningful Units of Work

Functional Programming

Com S 541. Programming Languages I

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Basics

PROGRAMMING LANGUAGE PARADIGMS & THE MAIN PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Haskell Programming

CS 342 Lecture 6 Scheme Procedures and Closures By: Hridesh Rajan

Functional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur

Programming Systems in Artificial Intelligence Functional Programming

G Programming Languages - Fall 2012

Programming Languages. Function-Closure Idioms. Adapted from Dan Grossman's PL class, U. of Washington

More Lambda Calculus and Intro to Type Systems

JVM ByteCode Interpreter

PROGRAMMING LANGUAGE PARADIGMS & THE MAIN PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING

Introduction to Functional Programming in Haskell 1 / 56

CS 242. Fundamentals. Reading: See last slide

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

Untyped Lambda Calculus

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION. Instructors: Crista Lopes Copyright Instructors.

Functional Programming. Contents

Imperative languages

An Embedded Domain Specific Language to Model, Transform and Quality Assure Business Processes in Business-Driven Development

Programming language design and analysis

CS 314 Principles of Programming Languages

CSCE 314 Programming Languages

Untyped Lambda Calculus

Chapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes

One of a number of approaches to a mathematical challenge at the time (1930): Constructibility

Functional Programming Languages (FPL)

Functional Programming Language Haskell

Lambda Calculus LC-1

Robot Programming with Lisp

Functional Programming in C++

Lambda Calculus see notes on Lambda Calculus

This session. Recursion. Planning the development. Software development. COM1022 Functional Programming and Reasoning

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland

More Lambda Calculus and Intro to Type Systems

Fifth Generation CS 4100 LISP. What do we need? Example LISP Program 11/13/13. Chapter 9: List Processing: LISP. Central Idea: Function Application

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Background Type Classes (1B) Young Won Lim 6/28/18

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

CS 415 Midterm Exam Spring 2002

Declarative concurrency. March 3, 2014

Recursion. Lecture 6: More Lambda Calculus Programming. Fixed Points. Recursion

Design Approaches for Concurrent Systems. CSCI 5828: Foundations of Software Engineering Lecture 08 02/09/2012

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Grafting Functional Support on Top of an Imperative Language

The role of semantic analysis in a compiler

Haskell in the Software Industry

CS422 - Programming Language Design

B16 Object Oriented Programming

Transcription:

Presented By Andrew Butt

Overview A Brief History of Functional Programming Comparison Between OOP and Functional programming Paradigms and Concepts Functional Programming in Other Languages

An Overview of Functional Programming

What is Functional Programming? Programming Paradigm with roots in Lambda Calculus and Combinatory logic Lambda calculus provides a formal system for definition, function application and recursion Treats computation as evaluation of mathematical functions without states Realizes a computation by composing functions

History On of the first languages LISP was developed in 1950s at MIT for IBM scientific computers Languages developed throughout 60s and 70s Haskell was released in 1980s in an attempt to unify many functional languages Referred to as the Algebra of Programming

An Overview of Functional Programming

Object Oriented Programming OOP has Objects Objects hide data, encapsulate Objects perform a set of related operations through methods Objects are capable of storing data on the current state of itself or other objects Objects are highly reusable

Functional Programming Takes a set of instructions to perform a task Selectively executing instructions can perform a task Pure Functions contain no mutable data Pure Functions are calculated solely on the data passed into them Calling foo(a,b) will always produce the same result

Definition of Function Functional Languages use Function in the mathematical use of the word Map input values to the output values Imperative Functions can be considered subroutines which subroutines with states and mutable data

Pure Functions Have no memory Will always result in the same answer when called with equivalent parameters If all calls are Pure functions then very If all calls are Pure functions then very efficient optimization is capable through the complier, as functions can be reordered or combined as needed.

Higher-order functions Can only take other functions as arguments Can return functions Analogous to returning d/dx when returning a derivative function Can enable currying: a function takes multiple arguments in such a way that it can be called as a chain of functions each with a single argument

Currying Example Using F(x,y) = x 2 / y 3 Evaluate F(5,5) Replacing x with 5 results in a new function in y: g(y) = 5 2 / y 3 Replacing y with 5 results in: g(3) = 25 / 5 3 g(3) = 1/5 Each step results in a more simplified expression

Functions Functions don t DO anything! That is they only return a value, no side effects will occur after the execution of a function For example no files can be written using pure functions and no variables will be changed in memory

A Little White Lie No file or I/O would do little more than warm up your computer Functional languages can actually write data and I/O using Non-Pure functions Purely functional languages only allow this inside language constructs Greatly limits side-effects

Faking States Many programs are closely tied to idea of states Functional languages can use monads to use I/O and mutable data Abstract this functionality away to maintain pureness

Functional Programming No loops! NONE! Nadda! Zip! Zilch! Loops are replaced with recursion

Efficiency Slower in many cases than imperative languages Very efficient at large matrix calculations Optimized for array functional languages

An Overview of Functional Programming

Strict Evaluation In strict evaluation any function which contains a failing term will also fail Eg: print length([5+2], 3*3, 6/0]) will fail due to divide by zero error Non-Strict (lazy) Evaluation Length will return 3, as its terms are not evaluated Lazy evaluation does not fully evaluate the expression before invoking a function.

Coding Techniques Steps are usually combined to emphasize composition and arrangement of functions, often without explicit steps defined. Imperitive style: target = List[]; for (item : source){ x = G(item) Y = F(trans1) target.append(trans2) } Functional Style: compose2 = lambda A, B: lambda x: A(B(x)) target = map(compose2(f, G), source)

Recursion Widely used in functional languages Largely replaces iteration, as functions invoke themselves Most functional languages allow unrestricted recursion and are Turing Complete Halting Problem is undecidable in many Functional Languages

Problems with Functional Programming As systems grow they become a large collection of functions All of these functions are interconnected Changing one function breaks all others relying on it Very hard to manage on large scales

An Example: Functional Factorial Haskell: factorial :: Integer -> Integer factorial 0 = 1 factorial n n > 0 = n * factorial (n-1) Line 1: defines the factorial function to take an integer and return an integer Line 2: Return 1 if input is 0 Line 3: if n > 0 call factorial on itself

An Example: Functional Factorial Common Lisp: (defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1)))))

An Overview of Functional Programming

Functional Programming in C Function pointers can be used in similar fashion as higher-order functions In C# lambda functions can used to program in a functional style Lazy evaluation can be used for lists in C Closures are possible in C through the use of pointers

Functional Programming in Java Runnable foo= new Runnable() { public void run() { bar(); } }; Bar is enclosed within the Runnable foo, and can be passed between methods as if it were data and executed at anytime by foo.run()

Why Use Functional Programming? Advantages in Parallel and concurrent programming by eliminating race conditions and locking of mutable data Very common in research and academia (Mathematica is a functional language) Testing can be easier as every function can be seen as independent

Why You May Not Want To Use Functional Programming! It requires a lot of overhead learning (and unlearning!) Most computer hardware implement optimization for imperative techniques Many problems are simply better suited for OOP or similar techniques

References or How I learned to Stop Asking Questions and RTM Konrad Hinsen, "The Promises of Functional Programming," Computing in Science and Engineering, vol. 11, no. 4, pp. 86-90, July/Aug. 2009, doi:10.1109/mcse.2009.129 Turner, D.A, Total Functional Programming, Journal of Universal Computer Science, vol. 10, no. 7, Jun 04 Hughes, John, Why Functional Programming Matters, 1984

Thank You!