301AA - Advanced Programming [AP-2017]
|
|
- Robert Lane
- 6 years ago
- Views:
Transcription
1 301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP : Func'onal Programming
2 FuncLonal Programming: Historical Origins The imperalve and funclonal models grew out of work undertaken Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s different formalizalons of the nolon of an algorithm, or effec,ve procedure, based on automata, symbolic manipulalon, recursive funclon definilons, and combinatorics These results led Church to conjecture that any intuilvely appealing model of compulng would be equally powerful as well this conjecture is known as Church s thesis 2
3 Historical Origins Church s model of compulng is called the lambda calculus based on the nolon of parameterized expressions (parameter introduced leber λ, hence the notalon s name) allows one to define mathemalcal funclons in a construclve/effeclve way lambda calculus was the inspiralon for funclonal programming computalon proceeds by subsltulng parameters into expressions, just as one computes in a high level funclonal program by passing arguments to funclons We shall see later the basic of lambda-calculus 3
4 FuncLonal Programming Concepts FuncLonal languages such as Lisp, Scheme, FP, ML, Miranda, and Haskell are an abempt to realize Church s lambda calculus in praclcal form as a programming language The key idea: do everything by composing funclons no mutable state no side effects 4
5 FuncLonal Programming Concepts Necessary features, many of which are missing in some imperalve languages: 1st class and high-order funclons recursion Takes the place of iteralon powerful list facililes Recursive funclon exploit recursive definilon of lists Polymorphism (typically universal parametric implicit) Relevance of Container/CollecLons fully general aggregates Data structures cannot be modified, have to be re-created structured funclon returns garbage colleclon Unlimited extent for locally allocated data structures 5
6 Other Related Concepts Lisp also has some features that are not necessary present in other funclonal languages: programs are data self-definilon read-evaluate-print interaclve loop Variants of LISP (Original) Lisp: purely funclonal, dynamically scoped Common Lisp: current standard, stalcally scoped, very complex Scheme: stalcally scoped, very elegant, used for teaching 6
7 Other funclonal languages: the ML family Robin Milner (Turing award in 1991, CCS, Pi-calculus, ) StaLcally typed, general-purpose programming language Meta-Language of the LCF theorem proving system Type safe, with type inference and formal semanlcs Compiled language, but intended for interaclve use CombinaLon of Lisp and Algol-like features Expression-oriented Higher-order funclons Garbage colleclon Abstract data types Module system ExcepLons 7
8 Other funclonal languages: Haskell Designed by commibee in 80 s and 90 s to unify research efforts in lazy languages EvoluLon of Miranda Haskell 1.0 in 1990, Haskell 98, Haskell 2010 Several features in common with ML, but some differ: Types and type checking Type inference Implicit parametric polymorphism Ad hoc polymorphism (overloading) Control Lazy vs. eager evalua@on Tail recursion and conlnualons Purely funclonal Precise management of effects 8
9 Downloading Haskell hbps:// 9
10 Core Haskell Basic Types Unit Booleans Integers Strings Reals Tuples Lists Records PaBerns DeclaraLons FuncLons Polymorphism Type declaralons Type Classes Monads ExcepLons 10
11 Overview of Haskell InteracLve Interpreter (ghci): read-eval-print ghci infers type before compiling or execulng Type system does not allow casts or similar things! Examples Prelude> 5==4 False Prelude> :set +t -- enables printing of types Prelude> 'x' 'x' it :: Char Prelude> (5+3)-2 6 it :: Num a => a --?? generic constrained type Prelude> :t map -- type of a function map :: (a -> b) -> [a] -> [b] 11
12 Booleans Overview by Type True, False :: Bool not :: Bool -> Bool and, or :: Foldable t => t Bool -> Bool if then else --types must match Characters & Strings 'a','b',';','\t', '2', 'X' :: Char "Ron Weasley" :: [Char] --strings are lists of chars 12
13 Numbers Overview by Type 0,1,2, :: Num p => p --type classes to disambiguate 1.0, :: Fractional a => a -> a -> a (45 :: Integer) :: Integer -- explicit typing +, *, -, :: Num a => a -> a -> a -- infix + becomes prefix (+) -- prefix binary op becomes infix `op` / :: Fractional a => a -> a -> a div, mod :: Integral a => a -> a -> a ^ :: (Num a, Integral b) => a -> b -> a 13
14 Simple Compound Types Tuples ("AP",2017) :: Num b => ([Char], b) -- pair fst :: (a, b) -> a snd :: (a, b) -> b ('4', True, "PLP") :: (Char, Bool, [Char]) Lists [] :: [a] -- NIL, polymorphic type 1 : [2, 3, 4] :: [Integer] -- infix cons notation [1,2]++[3,4] :: [Integer] -- concatenation Records data Person = Person {firstname :: String, lastname :: String} hg = Person { firstname = "Hermione", lastname = "Granger"} 14
15 More on list constructors ghci> [1..20] -- ranges [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] ghci> ['a'..'z'] "abcdefghijklmnopqrstuvwxyz" ghci> [3,6..20] -- ranges with step [3,6,9,12,15,18] ghci> [7,6..1] [7,6,5,4,3,2,1] ghci> [1..] -- an infinite list: runs forever ghci> take 10 [1..] -- prefix of an infinite lists [1,2,3,4,5,6,7,8,9,10] -- returns! ghci> take 10 (cycle [1,2]) [1,2,1,2,1,2,1,2,1,2] ghci> take 10 (repeat 5) [5,5,5,5,5,5,5,5,5,5] How does it work??? Later 15
16 PaBerns and DeclaraLons PaBerns can be used in place of variables <pat> ::= <var> <tuple> <cons> <record> Value declaralons General form: <pat> = <exp> Examples mytuple = ("Foo", "Bar") (x,y) = mytuple -- x = "Foo, y = "Bar" mylist = [1, 2, 3, 4] z:zs = mylist -- z = 1, zs = [2,3,4] Local declaralons let (x,y) = (2, "FooBar") in x * 4 16
17 Anonymous FuncLons (lambda abstraclon) Anonymous funclons \x -> x+1 --like Lisp lambda, function ( ) in JS (\x -> x+1)5 => 6 f = \x -> x+1 f 7 => 8 Anonymous funclons using paberns Prelude> h = \(x,y) -> x+y h :: Num a => (a, a) -> a Prelude> h (3, 4) => 7 Prelude> h 3 4 => error Prelude> k = \(z:zs) -> length zs k :: [a] -> Int Prelude> k "hello => 4 17
18 FuncLon declaralons FuncLon declaralon form <name> <pat 1 > = <exp 1 > <name> <pat 2 > = <exp 2 > Examples f (x,y) = x+y --argument must match pattern (x,y) length [] = 0 length (x:s) = 1 + length(s) 18
19 More FuncLons on Lists Apply funclon to every element of list map f [] = [] map f (x:xs) = f x : map f xs map (\x -> x+1) [1,2,3] [2,3,4] Reverse a list reverse [] = [] -- quadratic reverse (x:xs) = (reverse xs) ++ [x] reverse xs = -- linear, tail recursive let rev ( [], accum ) = accum rev ( y:ys, accum ) = rev ( ys, y:accum ) in rev ( xs, [] ) 19
20 On laziness Haskell is a lazy language FuncLons and data constructors don t evaluate their arguments unll they need them In several languages there are forms of lazy evalualons (if-then-else, shortcuwng && and )! if (x!= 0) return y/x; else return 0; //ok! if (x!=0 && y/x > 5) return 0; else return 1; //ok! if (x!=0 & y/x > 5) return 0; else return 1; //no!! int choose(boolean e1, boolean e2){! if (e1 && e2) return 0; else return 1;! }! choose(x!=0, y/x>5) //???! Ok in Haskell, thanks to Normal Order evalua@on and Call by Need parameter passing 20
21 A digression on λ-calculus 21
22 λ-calculus: syntax λ-terms: t ::= x λx.t t t (t) x variable, name, symbol, λx.t abstrac'on, defines an anonymous funclon t t' applica'on of funclon t to argument t Terms can be represented as abstract syntax trees SyntacLc ConvenLons ApplicaLons associates to lez t 1 t 2 t 3 (t 1 t 2 ) t 3 The body of abstraclon extends as far as possible λx. λy. x y x λx. (λy. (x y) x) A simple tutorial on lambda calculus: 22
23 Free vs. Bound Variables An occurrence of x is free in a term t if it is not in the body of an abstraclon λx. t otherwise it is bound λx is a binder Examples λz. λx. λy. x (y z) (λx. x) x Terms without free variables are combinators IdenLty funclon: id = λx. x First projeclon: fst = λx. λy. x
24 OperaLonal SemanLcs [β-reduclon] func'on applica'on redex (λx.t) t' = t [t'/x] (λ x. x) y (λ x. x (λ x. x) ) (u r) y u r (λ x.x) (λ x (λw. x w)) (y z) λw. y z w
25 λ-calculus as a funclonal language Despite the simplicity, we can encode in λ- calculus most concepts of funclonal languages: FucLons with several arguments Booleans and logical conneclves Integers and operalons on them Pairs and tuples 25
26 FuncLons with several arguments A definilon of a funclon with a single argument associates a name with a λ-abstraclon f x = <exp> f = λx.<exp> -- is equivalent to A funclon with several argument is equivalent to a sequence of λ-abstraclons f(x,y) = <exp> -- is equivalent to f = λx.λy.<exp> Currying and Uncurrying curry :: ((a, b) -> c) -> a -> b -> c uncurry :: (a -> b -> c) -> (a, b) -> c
27 Church Booleans T = λt.λf.t -- first! F = λt.λf.f -- second! and = λb.λc.bcf! or = λb.λc.btc! not = λx.xft! test =λl.λm.λn.lmn! test F u w! à (λl.λm.λn.lmn) F u w! à (λm.λn.fmn) u w! à (λn.fun) w! à Fuw! à w! and T F! à (λb.λc.bcf) T F! à (λc.tcf) F! à TFF! à F! not F! à (λx.xft) F! à FFT! à T!
28 Pairs pair = λf.λs.λb.b f s! fst = λp.p T! snd = λp.p F! fst (pair u w)! à (λp.p T) (pair u w)! à (pair u w) T! à (λf.λs.λb.b f s) u w T! à (λs.λb.b u s) w T! à (λb.b u w) T! à T u w! à u!
29 Numerals c 0 = λs. λz. z! c 1 = λs. λz. s z! c 2 = λs. λz. s (s z)! c 3 = λs. λz. s (s (s z))! succ = λn. λs. λz. s (n s z)! plus = λm. λn. λs. λz. m s (n s z)! times = λm. λn. m (plus n) c 0! Turing Complete! succ c2! à (λn. λs. λz. s (n s z)) c2! à (λs. λz. s (c2 s z))! à (λs. λz. s ((λs. λz. s (s z)) s z))! à (λs. λz. s (s (s z)) = c3!
Principles of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp-14/ Prof. Andrea Corradini Department of Computer Science, Pisa Func;onal programming languages Introduc;on to Hakell Lesson
More information301AA - Advanced Programming
301AA - Advanced Programming Lecturer: Andrea Corradini andrea@di.unipi.it h;p://pages.di.unipi.it/corradini/ Course pages: h;p://pages.di.unipi.it/corradini/dida@ca/ap-18/ AP-2018-18: Lambda Calculus,
More informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Introduc;on to Hakell Lesson 27! 1 The origins: ML programming
More information301AA - Advanced Programming [AP-2017]
301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2017-16: Haskell,
More informationChapter 11 :: Functional Languages
Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Copyright 2016 Elsevier 1 Chapter11_Functional_Languages_4e - Tue November 21, 2017 Historical Origins The imperative
More informationFunctional Languages. CSE 307 Principles of Programming Languages Stony Brook University
Functional Languages CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Historical Origins 2 The imperative and functional models grew out of work
More informationProgramming Language Pragmatics
Chapter 10 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken Alan Turing, Alonzo Church, Stephen
More informationFunctional Languages. Hwansoo Han
Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm
More information4/19/2018. Chapter 11 :: Functional Languages
Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken by Alan Turing, Alonzo Church, Stephen
More informationIntroduction to Haskell
CS 242 Autumn 2012 Introduction to Haskell (slides modified from those created by John Mitchell and Kathleen Fisher) Language Evolution Lisp Algol 60 Algol 68 Pascal C Smalltalk ML Modula C++ Haskell Java
More informationIntroduction to ML. Based on materials by Vitaly Shmatikov. General-purpose, non-c-like, non-oo language. Related languages: Haskell, Ocaml, F#,
Introduction to ML Based on materials by Vitaly Shmatikov slide 1 ML General-purpose, non-c-like, non-oo language Related languages: Haskell, Ocaml, F#, Combination of Lisp and Algol-like features (1958)
More informationCIS 500 Software Foundations Fall September 25
CIS 500 Software Foundations Fall 2006 September 25 The Lambda Calculus The lambda-calculus If our previous language of arithmetic expressions was the simplest nontrivial programming language, then the
More informationRecursion. Lecture 6: More Lambda Calculus Programming. Fixed Points. Recursion
Recursion Lecture 6: More Lambda Calculus Programming CSC 131! Fall, 2014!! Kim Bruce Recursive definitions are handy! - fact = λn. cond (iszero n) 1 (Mult n (fact (Pred n)))! - Not a legal definition
More informationCOP4020 Programming Languages. Functional Programming Prof. Robert van Engelen
COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts
More informationHaskell Introduction Lists Other Structures Data Structures. Haskell Introduction. Mark Snyder
Outline 1 2 3 4 What is Haskell? Haskell is a functional programming language. Characteristics functional non-strict ( lazy ) pure (no side effects*) strongly statically typed available compiled and interpreted
More informationProgramming Languages Fall 2013
Programming Languages Fall 2013 Lecture 2: types Prof. Liang Huang huang@qc.cs.cuny.edu Recap of Lecture 1 functional programming vs. imperative programming basic Haskell syntax function definition lazy
More informationAccording to Larry Wall (designer of PERL): a language by geniuses! for geniuses. Lecture 7: Haskell. Haskell 98. Haskell (cont) - Type-safe!
Lecture 7: Haskell CSC 131 Fall, 2014 Kim Bruce According to Larry Wall (designer of PERL): a language by geniuses for geniuses He s wrong at least about the latter part though you might agree when we
More information301AA - Advanced Programming [AP-2017]
301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2017-19: Type
More informationHaske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell
Haskell An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dk The most popular purely functional, lazy programming language Functional programming language : a program
More informationType Systems Winter Semester 2006
Type Systems Winter Semester 2006 Week 4 November 8 November 15, 2006 - version 1.1 The Lambda Calculus The lambda-calculus If our previous language of arithmetic expressions was the simplest nontrivial
More informationIntroduction to Haskell
Spring 2012 Introduction to Haskell Mooly Sagiv (original slides by Kathleen Fisher & John Mitchell) Lambda Calculus Computation Models Turing Machines Wang Machines Lambda Calculus Untyped Lambda Calculus
More informationAn introduction introduction to functional functional programming programming using usin Haskell
An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dkau Haskell The most popular p purely functional, lazy programming g language Functional programming language : a program
More information10/21/08. Kathleen Fisher! Question:! Interesting answer in Algol:!
cs4! Lisp! Algol 60! Algol 68! Kathleen Fisher! ML! Pascal! Modula! Reading: Concepts in Programming Languages Chapter 5 except 5.4.5! Real World Haskell, Chapter 0 and Chapter! (http://book.realworldhaskell.org/)!
More informationImperative languages
Imperative languages Von Neumann model: store with addressable locations machine code: effect achieved by changing contents of store locations instructions executed in sequence, flow of control altered
More informationLecture 9: More Lambda Calculus / Types
Lecture 9: More Lambda Calculus / Types CSC 131 Spring, 2019 Kim Bruce Pure Lambda Calculus Terms of pure lambda calculus - M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete
More information- M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete. - true = λ u. λ v. u. - false = λ u. λ v.
Pure Lambda Calculus Lecture 9: More Lambda Calculus / Types CSC 131 Spring, 2019 Kim Bruce Terms of pure lambda calculus - M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete
More informationChapter 5: The Untyped Lambda Calculus
Chapter 5: The Untyped Lambda Calculus What is lambda calculus for? Basics: syntax and operational semantics Programming in the Lambda Calculus Formalities (formal definitions) What is Lambda calculus
More informationn n Try tutorial on front page to get started! n spring13/ n Stack Overflow!
Announcements n Rainbow grades: HW1-6, Quiz1-5, Exam1 n Still grading: HW7, Quiz6, Exam2 Intro to Haskell n HW8 due today n HW9, Haskell, out tonight, due Nov. 16 th n Individual assignment n Start early!
More informationFunctional Programming
Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used
More informationFunctional Programming
Functional Programming COMS W4115 Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Original version by Prof. Simon Parsons Functional vs. Imperative Imperative programming
More informationThe Lambda Calculus. 27 September. Fall Software Foundations CIS 500. The lambda-calculus. Announcements
CIS 500 Software Foundations Fall 2004 27 September IS 500, 27 September 1 The Lambda Calculus IS 500, 27 September 3 Announcements Homework 1 is graded. Pick it up from Cheryl Hickey (Levine 502). We
More informationFunctional Languages and Higher-Order Functions
Functional Languages and Higher-Order Functions Leonidas Fegaras CSE 5317/4305 L12: Higher-Order Functions 1 First-Class Functions Values of some type are first-class if They can be assigned to local variables
More information9/28/09. Kathleen Fisher. Question: Interesting answer in Algol:
cs4 Lisp Algol 60 Algol 68 Kathleen Fisher Pascal C Smalltalk Reading: Concepts in Programming Languages Chapter 5 except 5.4.5 Real World Haskell, Chapter 0 and Chapter (http://book.realworldhaskell.org/)
More informationLECTURE 16. Functional Programming
LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative
More information301AA - Advanced Programming
301AA - Advanced Programming Lecturer: Andrea Corradini andrea@di.unipi.it h;p://pages.di.unipi.it/corradini/ Course pages: h;p://pages.di.unipi.it/corradini/dida@ca/ap-18/ AP-2018-19: Algebraic Datatypes
More information4/13/15. Kathleen Fisher for cs242 at Tufts Lightly edited with permission, Michelle Strout 4/10/15
Lisp Algol 60 Algol 68 Kathleen Fisher for cs242 at Tufts Lightly edited with permission, Michelle Strout 4/0/5 Real World Haskell, Chapter 0 and Chapter (http://book.realworldhaskell.org/) Haskell ML
More informationLanguage Sequence. The Algol Family and ML. Algol 60 Sample. Algol 60. Some trouble spots in Algol 60. Algol Joke. John Mitchell
CS 4 Language Sequence The Algol Family and ML Lisp Algol 60 John Mitchell Algol 68 Pascal ML Modula Reading: Chapter 5 Many other languages: Algol 58, Algol W, Euclid, EL, Mesa (PARC), Modula-, Oberon,
More informationCS 11 Haskell track: lecture 1
CS 11 Haskell track: lecture 1 This week: Introduction/motivation/pep talk Basics of Haskell Prerequisite Knowledge of basic functional programming e.g. Scheme, Ocaml, Erlang CS 1, CS 4 "permission of
More informationPractical Haskell. An introduction to functional programming. July 21, Practical Haskell. Juan Pedro Villa-Isaza. Introduction.
Practical Practical An introduction to functional programming July 21, 2011 Contents Practical Practical is fun, and that s what it s all about! Even if seems strange to you at first, don t give up. Learning
More information9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete
Dr A Sahu Dept of Computer Science & Engineering IIT Guwahati Why study? Lambda calculus Syntax Evaluation Relationship to programming languages Church Rosser theorem Completeness of Lambda Calculus: Turing
More informationCSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.
CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:
More informationCSCI-GA Scripting Languages
CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation
More informationGraphical Untyped Lambda Calculus Interactive Interpreter
Graphical Untyped Lambda Calculus Interactive Interpreter (GULCII) Claude Heiland-Allen https://mathr.co.uk mailto:claude@mathr.co.uk Edinburgh, 2017 Outline Lambda calculus encodings How to perform lambda
More informationPrinciples of Programming Languages COMP251: Functional Programming in Scheme (and LISP)
Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology
More informationFunctional Programming. Overview. Topics. Definition n-th Fibonacci Number. Graph
Topics Functional Programming Christian Sternagel Harald Zankl Evgeny Zuenko Department of Computer Science University of Innsbruck WS 2017/2018 abstract data types, algebraic data types, binary search
More informationHaskell An Introduction
Haskell An Introduction What is Haskell? General purpose Purely functional No function can have side-effects IO is done using special types Lazy Strongly typed Polymorphic types Concise and elegant A First
More informationProgramming with Math and Logic
.. Programming with Math and Logic an invitation to functional programming Ed Morehouse Wesleyan University The Plan why fp? terms types interfaces The What and Why of Functional Programming Computing
More informationHaskell 101. (Version 1 (July 18, 2012)) Juan Pedro Villa Isaza
Haskell 101 (Version 1 (July 18, 2012)) Juan Pedro Villa Isaza Haskell 101: Contents Introduction Tutorial Homework Bibliography Haskell 101: Contents Introduction Tutorial Homework Bibliography Haskell
More informationFunctional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur
Functional Programming and λ Calculus Amey Karkare Dept of CSE, IIT Kanpur 0 Software Development Challenges Growing size and complexity of modern computer programs Complicated architectures Massively
More informationM. Snyder, George Mason University LAMBDA CALCULUS. (untyped)
1 LAMBDA CALCULUS (untyped) 2 The Untyped Lambda Calculus (λ) Designed by Alonzo Church (1930s) Turing Complete (Turing was his doctoral student!) Models functions, always as 1-input Definition: terms,
More informationLecture 19: Functions, Types and Data Structures in Haskell
The University of North Carolina at Chapel Hill Spring 2002 Lecture 19: Functions, Types and Data Structures in Haskell Feb 25 1 Functions Functions are the most important kind of value in functional programming
More informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp-16/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 24! Type inference in ML / Haskell 1 Type Checking vs
More informationλ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods
Course 2D1453, 2006-07 Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Alonzo Church, 1903-1995 Church-Turing thesis First
More informationCSE 3302 Programming Languages Lecture 8: Functional Programming
CSE 3302 Programming Languages Lecture 8: Functional Programming (based on the slides by Tim Sheard) Leonidas Fegaras University of Texas at Arlington CSE 3302 L8 Spring 2011 1 Functional Programming Languages
More informationFunctional Programming. Pure Functional Programming
Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).
More informationTypes and Type Inference
CS 242 2012 Types and Type Inference Notes modified from John Mitchell and Kathleen Fisher Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on Web!! Outline General discussion of
More informationλ-calculus Lecture 1 Venanzio Capretta MGS Nottingham
λ-calculus Lecture 1 Venanzio Capretta MGS 2018 - Nottingham Table of contents 1. History of λ-calculus 2. Definition of λ-calculus 3. Data Structures 1 History of λ-calculus Hilbert s Program David Hilbert
More informationCSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Basics
1 CSCE 314: Programming Languages Dr. Flemming Andersen Haskell Basics 2 Contents 1. Jump into Haskell: Using ghc and ghci (more detail) 2. Historical Background of Haskell 3. Lazy, Pure, and Functional
More informationFunctional Programming. Overview. Topics. Recall λ-terms. Examples
Topics Functional Programming Christian Sternagel Harald Zankl Evgeny Zuenko Department of Computer Science University of Innsbruck WS 2017/2018 abstract data types, algebraic data types, binary search
More informationFundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP)
Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology
More informationIntroduction to OCaml
Fall 2018 Introduction to OCaml Yu Zhang Course web site: http://staff.ustc.edu.cn/~yuzhang/tpl References Learn X in Y Minutes Ocaml Real World OCaml Cornell CS 3110 Spring 2018 Data Structures and Functional
More informationIntroduction. chapter Functions
chapter 1 Introduction In this chapter we set the stage for the rest of the book. We start by reviewing the notion of a function, then introduce the concept of functional programming, summarise the main
More informationAn introduction to functional programming. July 23, 2010
An introduction to functional programming July 23, 2010 About Outline About About What is functional programming? What is? Why functional programming? Why? is novel. is powerful. is fun. About A brief
More informationIntroduction to Lambda Calculus. Lecture 5 CS 565 1/24/08
Introduction to Lambda Calculus Lecture 5 CS 565 1/24/08 Lambda Calculus So far, we ve explored some simple but non-interesting languages language of arithmetic expressions IMP (arithmetic + while loops)
More informationIt is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis
Chapter 14 Functional Programming Programming Languages 2nd edition Tucker and Noonan It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis
More information5. Introduction to the Lambda Calculus. Oscar Nierstrasz
5. Introduction to the Lambda Calculus Oscar Nierstrasz Roadmap > What is Computability? Church s Thesis > Lambda Calculus operational semantics > The Church-Rosser Property > Modelling basic programming
More informationExercise 1 ( = 24 points)
1 Exercise 1 (4 + 5 + 4 + 6 + 5 = 24 points) The following data structure represents polymorphic binary trees that contain values only in special Value nodes that have a single successor: data Tree a =
More information11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations
Outline FP Foundations, Scheme In Text: Chapter 15 Mathematical foundations Functional programming λ-calculus LISP Scheme 2 Imperative Languages We have been discussing imperative languages C/C++, Java,
More informationLecture #23: Conversion and Type Inference
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). Last modified: Fri Oct 20 10:46:40 2006 CS164:
More informationConversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";
More informationCS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus
CS 4110 Programming Languages & Logics Lecture 17 Programming in the λ-calculus 10 October 2014 Announcements 2 Foster Office Hours 11-12 Enjoy fall break! Review: Church Booleans 3 We can encode TRUE,
More informationCSCE 314 Programming Languages
CSCE 314 Programming Languages Haskell 101 Dr. Hyunyoung Lee 1 Contents 1. Historical Background of Haskell 2. Lazy, Pure, and Functional Language 3. Using ghc and ghci 4. Functions 5. Haskell Scripts
More informationIntroduction to Lambda Calculus. Lecture 7 CS /08/09
Introduction to Lambda Calculus Lecture 7 CS 565 02/08/09 Lambda Calculus So far, we ve explored some simple but non-interesting languages language of arithmetic expressions IMP (arithmetic + while loops)
More informationFunctional Programming
Functional Programming Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense September 5, 2017 Practical Information The course is split in two I am responsible
More informationHaskell Overview II (2A) Young Won Lim 8/9/16
(2A) Copyright (c) 2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published
More informationOrganization of Programming Languages CS3200/5200N. Lecture 11
Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages
More informationCITS3211 FUNCTIONAL PROGRAMMING. 10. Programming in the pure λ calculus
CITS3211 FUNCTIONAL PROGRAMMING 10. Programming in the pure λ calculus Summary: This lecture demonstates the power of the pure λ calculus by showing that there are λ expressions that can be used to emulate
More informationLecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference
Lecture #13: Type Inference and Unification Typing In the Language ML Examples from the language ML: fun map f [] = [] map f (a :: y) = (f a) :: (map f y) fun reduce f init [] = init reduce f init (a ::
More informationRecursive Definitions, Fixed Points and the Combinator
Recursive Definitions, Fixed Points and the Combinator Dr. Greg Lavender Department of Computer Sciences University of Texas at Austin Recursive Self-Reference Recursive self-reference occurs regularly
More informationHaskell: Lists. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, Glenn G.
Haskell: Lists CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks
More informationFormal Semantics. Aspects to formalize. Lambda calculus. Approach
Formal Semantics Aspects to formalize Why formalize? some language features are tricky, e.g. generalizable type variables, nested functions some features have subtle interactions, e.g. polymorphism and
More informationDenotational Semantics. Domain Theory
Denotational Semantics and Domain Theory 1 / 51 Outline Denotational Semantics Basic Domain Theory Introduction and history Primitive and lifted domains Sum and product domains Function domains Meaning
More informationFunctional Programming and Haskell
Functional Programming and Haskell Tim Dawborn University of Sydney, Australia School of Information Technologies Tim Dawborn Functional Programming and Haskell 1/22 What are Programming Paradigms? A programming
More informationLogic - CM0845 Introduction to Haskell
Logic - CM0845 Introduction to Haskell Diego Alejandro Montoya-Zapata EAFIT University Semester 2016-1 Diego Alejandro Montoya-Zapata (EAFIT University) Logic - CM0845 Introduction to Haskell Semester
More informationAnnouncements. CSCI 334: Principles of Programming Languages. Lecture 5: Fundamentals III & ML
Announcements CSCI 334: Principles of Programming Languages Lecture 5: Fundamentals III & ML Instructor: Dan Barowy Claire Booth Luce info session tonight for women interested in summer research (hopefully
More informationPure Lambda Calculus. Lecture 17
Pure Lambda Calculus Lecture 17 Lambda Calculus Lambda Calculus (λ-calculus) is a functional notation introduced by Alonzo Church in the early 1930s to formalize the notion of computability. Pure λ-calculus
More informationFormal Systems and their Applications
Formal Systems and their Applications Dave Clarke (Dave.Clarke@cs.kuleuven.be) Acknowledgment: these slides are based in part on slides from Benjamin Pierce and Frank Piessens 1 Course Overview Introduction
More informationPolymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy
06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 6: Polymorphic Type Systems 1. Polymorphic
More informationCS152: Programming Languages. Lecture 7 Lambda Calculus. Dan Grossman Spring 2011
CS152: Programming Languages Lecture 7 Lambda Calculus Dan Grossman Spring 2011 Where we are Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now:
More informationHaskell 5.1 INTERACTIVE SESSIONS AND THE RUN-TIME SYSTEM
5 Haskell Haskell is a lazy, functional programming language that was initially designed by a committee in the eighties and nineties. In contrast to many programming languages, it is lazy, meaning that
More informationFunctional Programming. Big Picture. Design of Programming Languages
Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics
More informationExercise 1 ( = 22 points)
1 Exercise 1 (4 + 3 + 4 + 5 + 6 = 22 points) The following data structure represents polymorphic lists that can contain values of two types in arbitrary order: data DuoList a b = C a (DuoList a b) D b
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 1 Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Use currying
More informationIntroduction to Haskell
Autumn 2017 Introduction to Haskell Mooly Sagiv (original slides by Kathleen Fisher & John Mitchell) Graham Hutton What is Functional Programming? Opinions differ, and it is difficult to give a precise
More informationOne of a number of approaches to a mathematical challenge at the time (1930): Constructibility
λ Calculus Church s λ Calculus: Brief History One of a number of approaches to a mathematical challenge at the time (1930): Constructibility (What does it mean for an object, e.g. a natural number, to
More informationCSE 505. Lecture #9. October 1, Lambda Calculus. Recursion and Fixed-points. Typed Lambda Calculi. Least Fixed Point
Lambda Calculus CSE 505 Lecture #9 October 1, 2012 Expr ::= Var λ Var. Expr (Expr Expr) Key Concepts: Bound and Free Occurrences Substitution, Reduction Rules: α, β, η Confluence and Unique Normal Form
More informationCS 320: Concepts of Programming Languages
CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 04: Basic Haskell Continued o Polymorphic Types o Type Inference with Polymorphism o Standard
More informationCOMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland
COMP 1130 Lambda Calculus based on slides by Jeff Foster, U Maryland Motivation Commonly-used programming languages are large and complex ANSI C99 standard: 538 pages ANSI C++ standard: 714 pages Java
More informationCostly software bugs that could have been averted with type checking
Type Checking Class Notes from Lectures 6 and 7 Lahav Yeffet and Ori Folger The material in these lectures is based on the textbook Types and Programming Languages by Benjamin Pierce. Here is a list of
More informationCS 457/557: Functional Languages
CS 457/557: Functional Languages Lists and Algebraic Datatypes Mark P Jones Portland State University 1 Why Lists? Lists are a heavily used data structure in many functional programs Special syntax is
More information