Functional Programming a (very) short introduction Ben Couste 06/10/2010.

Slides:



Advertisements
Similar presentations
Tree Recursion Traditional Approach. Tree Recursion Consider the Fibonacci Number Sequence: Time: , 1, 1, 2, 3, 5, 8, 13, 21,... /
Advertisements

1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
§3 Dynamic Programming Use a table instead of recursion 1. Fibonacci Numbers: F(N) = F(N – 1) + F(N – 2) int Fib( int N ) { if ( N
Types of Recursive Methods
Comp 205: Comparative Programming Languages Functional Programming Languages: More Haskell Nested definitions Lists Lecture notes, exercises, etc., can.
23 November 2007RCEAS 2007, Budapest1 Embedded Functional Programming Gergely Patai Budapest University of Technology and Economics Department.
Announcements Final Exam: Project Due on Wednesday at noon Central Time.
Chapter 15 Other Functional Languages. Copyright © 2007 Addison-Wesley. All rights reserved. Functional Languages Scheme and LISP have a simple syntax.
Monday, 12/9/02, Slide #1 CS 106 Intro to CS 1 Monday, 12/9/02  QUESTIONS??  On HW #5 (Due 5 pm today)  Today:  Recursive functions  Reading: Chapter.
CS 101 Course Summary December 5, Big Ideas Abstraction Problem solving Fundamentals of programming.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science pH: A Parallel Dialect of Haskell Jim Cipar & Jacob Sorber University of Massachusetts.
Programming Languages Structure
Advanced Programming Handout 11 Programming With Streams (SOE Chapter 14)
Recursion in Scheme recursion is the basic means for expressing repetition some recursion is on numbers –factorial –fibonacci some recursion is on structures.
Comp 205: Comparative Programming Languages Imperative Programming Languages Functional Programming Languages Semantics Other Paradigms Lecture notes,
Interlude: Functional Programming CSE 331 Section 2 James Daly.
Copyright © 2009 Elsevier Chapter 10 :: Functional Languages Programming Language Pragmatics Michael L. Scott.
Haskell Chapter 1, Part I. Highly Recommended  Learn you a Haskell for Great Good. Miran Lipovaca.
Haskell Chapter 8. Input and Output  What are I/O actions?  How do I/O actions enable us to do I/O?  When are I/O actions actually performed?
1 Programming Language History and Evolution In Text: Chapter 2.
Dan Johnson.  Functional language that started development in  Committee designed language  Pure and Lazy  Compiled or Interpreted  Named after.
CSC 580 – Theory of Programming Languages, Spring, 2009 Week 9: Functional Languages ML and Haskell, Dr. Dale E. Parson.
CS112: Structure of Programming Languages A smorgasbord of topics in programming languages including programming paradigms and syntax, semantics, implementation.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Chapter Fifteen: Functional Programming Languages Lesson 12.
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 6 Recursion.
Functional Programming Language OCaml Tutorial 科大 - 耶鲁联合研究中心
Going Functional Primož Gabrijelčič. Functional programming.
CS 345: Programming Language Paradigms Chris Brooks HR 510 MWF 11:00-12:05.
Comparative Programming Languages Language Comparison: Scheme, Smalltalk, Python, Ruby, Perl, Prolog, ML, C++/STL, Java, Haskell.
Languages and Compilers
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L13-1 October 26, 2006http:// Monadic Programming October.
Programming Languages
Infinite Geometric Series Recursion & Special Sequences Definitions & Equations Writing & Solving Geometric Series Practice Problems.
Functional Programming IN NON-FUNCTIONAL LANGUAGES.
CSE 341 Section 10 Subtyping, Review, and The Future.
Recursion in Java The answer to life’s greatest mysteries are on the last slide.
CS321 Functional Programming 2 © JAS Programming with Streams A stream is never finite and could be defined as special polymorphic type data stream.
Monads Technion – Institute of Technology Software Design (236700) Author: Gal Lalouche - Technion 2016 © 1.
서울대한양대 ( 안 산 ) 충남대 1년1년 컴퓨터기초 (C) 컴퓨터프로그래밍 (C, Java) 컴퓨터프로그래밍 (C) 2. 봄 프로그래밍 원리 (Scheme, ML) Structure & Interpretation of Computer Programs 프로그래밍 방법론.
Introduction to Concepts in Functional Programming CS16: Introduction to Data Structures & Algorithms Thursday, April 9,
24-Jun-16 Haskell Dealing with impurity. Purity Haskell is a “pure” functional programming language Functions have no side effects Input/output is a side.
a medium allowing humans and computers to communicate an abstraction of the real world a notation for expressing algorithms the set of all syntactically.
Introduction to Functional Programming Part 1 – The Basic Concepts Winter Young
Programming Language History and Evolution
Haskell Chapter 8.
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2017.
Theory of Computation Lecture 4: Programs and Computable Functions II
CS 3304 Comparative Languages
CSE 341 Lecture 5 efficiency issues; tail recursion; print
Comp 205: Comparative Programming Languages
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Winter 2013.
Sequences and Series.
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2013.
Functional Programming
Midterm Review In Text: Chapters 1-3, 5, 15.
LECTURE 31: INTRO TO FUNCTIONAL PROGRAMMING
FP Foundations, Scheme In Text: Chapter 14.
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2016.
Organization of Programming Languages
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Autumn 2017.
CS 36 – Chapter 11 Functional programming Features Practice
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Autumn 2018.
Announcements Final Exam: Project Due on Monday at noon Central Time.
Overview of Programming Paradigms
Functional Programming and Haskell
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2019.
Functional Programming and Haskell
Presentation transcript:

Functional Programming a (very) short introduction Ben Couste 06/10/2010

Functional Programming “ML, Lisp, and Haskell are the only programming languages that I've seen where one spends more time thinking than typing.” - Philip Greenspun

Outline What is Functional Programming (FP)? Why would I want to use it? Examples!

What is FP? Different paradigm Imperative programming (think C or Java) is about changes in the state of data Functional programming is about the application of functions Writing “pure” code

Barrier to entry Different programming paradigm “A monad is just a monoid in the category of endofunctors!” Mathematicians love FP Large and intimidating community (#haskell on irc.freenode.org) Generally very business-unfriendly

Purity Pure code has no side effects Easier to debug! Not always possible (I/O, mutable arrays)

Typing Write well-typed programs Program will not compile otherwise!

Recursion example Classic method in CS Heavily used in FP Each new term in the Fibonacci sequence is generated by adding the previous two terms. Find the sum of all the even-valued terms in the sequence which do not exceed four million. (project-euler.net)

Haskell Implementation Prelude> let fibs = 0 : 1 : zipWith (+) fibs (tail fibs) Prelude> sum [x | x <- (takeWhile (< ) fibs), even x]

Shifting functions around Functions can be passed as parameters! Code reuse anyone? Syntactic sugar Fun!

Further reading My handouts on the course website