Case study: leical analysis Leical analysis converts u sequences of characters u into u sequences of tokens u tokens are also called words or leemes F
|
|
- Gillian Perkins
- 6 years ago
- Views:
Transcription
1 Lecture 5 0
2 Case study: leical analysis Leical analysis converts u sequences of characters u into u sequences of tokens u tokens are also called words or leemes For us, a token will be one of: u a number (sequence of digits) u an identier (sequence of letters or digits starting with a letter) u a `special symbol' such as +, *, <, ==> or ++ u special symbols are specied by a table { see later 1
3 Numbers and letters A number is a sequence of digits <= is overloaded and can be applied to strings u suppose and y are single-character strings u then <=y just tests whether the ASCII code of is less then or equal to the ASCII code of y fun IsDigit = "0" <= andalso <= "9"; > val IsDigit = fn : string -> bool ASCII codes of lower case letters are adjacent ASCII codes of upper case letters are adjacent fun IsLetter = ("a" <= andalso <= "z") orelse ("A" <= andalso <= "Z"); > val IsLetter = fn : string -> bool 2
4 Separators Separators are spaces, newlines and tabs fun IsSeparator = ( = " " orelse = "\n" orelse = "\t"); > val IsSeparator = fn : string -> bool Characters that are not digits, letters or separators are assumed to be special symbols u multi-character special symbols are considered later Input a list of single-charater strings u leical analysis converts input to a token list 3
5 Special case: only numbers Suppose input just consists of numbers separated by separators Leical analysis for just this case needs to: u repeatedly remove digits until a non-number is reached u then implode the removed characters into a token u and add that to the list of tokens GetNumber takes a list, l say, of single-character strings and returns a pair consisting of u a string representing a number consisting of all the digits in l up to the rst non-digit u the remainder of l after these digits have been removed GetNum uses an auiliary function GetNumAu u GetNumAu has an etra argument buf for accumulating a (reversed) list of characters making up the number 4
6 GetNumAu and GetNum fun GetNumAu buf [] = (implode(rev buf), []) GetNumAu buf (l as (::l')) = if IsDigit then GetNumAu (::buf) l' else (implode(rev buf),l); > val GetNumAu = > fn > : string list -> string list -> string * string list GetNumAu ["a","b","c"] ["1","2","3"," ","4","5"]; > val it = > ("cba123",[" ","4","5"]) : string * string list Then GetNum is simply dened by: val GetNum = GetNumAu []; > val GetNum = fn : string list -> string * string list GetNum ["1","2","3"," ","4","5"]; > val it = ("123",[" ","4","5"]) : string * string list GetNum ["a","0","1"]; > val it = ("",["a","0","1"]) : string * string list Anomalous return of "" ed later Could localise denition of GetNumAu using local in end 5
7 Special case: only identiers Analysis of identiers similar to numbers fun GetIdentAu buf [] = (implode(rev buf), []) GetIdentAu buf (l as (::l')) = if IsLetter orelse IsDigit then GetIdentAu (::buf) l' else (implode(rev buf),l); > val GetIdentAu = > fn > : string list -> string list -> string * string list GetIdentAu ["a","b","c"] ["e","f","g","4","5"," ","6","7"]; > val it = > ("cbaefg45",[" ","6","7"]) : string * string list An identier must start with a letter eception GetIdentErr; > eception GetIdentErr fun GetIdent (::l) = if IsLetter then GetIdentAu [] l else raise GetIdentErr; > val GetIdent = > fn : string list -> string * string list 6
8 Unied treatment Can unify Analysis of numbers and identiers u single general function GetTail u takes a predicate as argument u then uses this to test whether to keep accumulating characters or to terminate u GetNumAu corresponds to GetTail IsDigit u GetIdentAu corresponds to GetTail (fn => IsLetter orelse IsDigit ) fun GetTail p buf [] = (implode(rev buf),[]) GetTail p buf (l as ::l') = if p then GetTail p (::buf) l' else (implode(rev buf),l); > val GetTail = fn > : (string->bool) > -> string list > -> string list -> string * string list 7
9 GetNetToken and Tokenise fun GetNetToken [] = (,[]) GetNetToken (::l) = if IsLetter then GetTail (fn => IsLetter orelse IsDigit ) [] l else if IsDigit then GetTail IsDigit [] l else (,l); > val GetNetToken = > fn : string list -> string * string list To leically analyse a list of characters: u repeat GetNetToken & discard separators fun Tokenise [] = [] Tokenise (l as ::l') = if IsSeparator then Tokenise l' else let val (t,l'') = GetNetToken l in t::(tokenise l'') end; > val Tokenise = fn : string list -> string list Tokenise (eplode "123abcde1][ ] 56a"); > val it = > ["123","abcde1","]","[","]","56","a"] : string list 8
10 Multi-character special symbols Tokenise doesn't handle multi-character special symbols u these will be specied by a table u represented as a list of pairs u that shows which characters can follow each initial segment of each special symbol u such a table represents a FSM transition function For eample, suppose the special symbols are <=, <<, =>, =, ==>, -> then the table would be: [("<", ["=","<"]), ("=", [">","="]), ("-", [">"]), ("==", [">"])] Not fully general u if ==> is a special symbol u then == must be also 9
11 Utility functions Test for membership fun Mem [] = false Mem ('::l) = (=') orelse Mem l; > val Mem = fn : ''a -> ''a list -> bool Get looks up the list of possible successors of a given string in a special-symbol table fun Get [] = [] Get ((',l)::rest) = if =' then l else Get rest; > val Get = fn : ''a -> (''a * 'b list) list -> 'b list Get "=" [("<",["=","<"]), ("=",[">","="]), ("-",[">"]), ("==",[">"])]; > val it = [">","="] : string list Get "?" [("<", ["=","<"]), ("=", [">","="]), ("-", [">"]), ("==",[">"])]; > val it = [] : string list 10
12 GetSymbol GetSymbol takes u a special-symbol table u and a token It etends the token by u removing characters from the input u until table says no further etension is possible fun GetSymbol spectab tok [] = (tok,[]) GetSymbol spectab tok (l as ::l') = if Mem (Get tok spectab) then GetSymbol spectab (tok^) l' else (tok,l); > val GetSymbol = fn > : (string * string list) list > -> string -> string list -> string * string list 11
13 GetNetToken GetNetToken can be enhanced to handle special symbols Special-symbol table supplied as an argument fun GetNetToken spectab [] = (,[]) GetNetToken spectab (::(l as '::l')) = if IsLetter then GetTail (fn => IsLetter orelse IsDigit ) [] l else if IsDigit then GetTail IsDigit [] l else if Mem ' (Get spectab) then GetSymbol spectab (implode[,']) l' else (,l); > val GetNetToken = fn > : (string * string list) list > -> string list -> string * string list 12
14 Tokenise Tokenise can be enhanced to use the new GetNetToken fun Tokenise spectab [] = [] Tokenise spectab (l as ::l') = if IsSeparator then Tokenise spectab l' else let val (t,l'') = GetNetToken spectab l in t::(tokenise spectab l'') end; > val GetNetToken = fn > : (string * string list) list > -> string list -> string * string list 13
15 Eample val SpecTab = [("=", ["<",">","="]), ("<", ["<",">"]), (">", ["<",">"]), ("==", [">"])]; > val SpecTab = > [("=",["<",">","="]), > ("<",["<",">"]), > (">",["<",">"]), > ("==",[">"])] > : (string * string list) list Tokenise SpecTab (eplode "a==>b c5 d5==ff+gg7"); > val it = > ["a","==>","b","c5","d5","==","ff","+","gg7"] > : string list Le is a leical analyser val Le = Tokenise SpecTab o eplode; > val Le = fn : string -> string list Le "a==>b c5 d5==ff+gg7"; > val it = > ["a","==>","b","c5","d5","==","ff","+","gg7"] > : string list 14
16 The -calculus The -calculus is a theory of functions u originally developed by Alonzo Church u as a foundation for mathematics u in the 1930s, several years before digital computers were invented In the 1920s Moses Schonnkel developed combinators In the 1930s, Haskell Curry rediscovered and etended Schonnkel's theory u and showed it equivalent to the -calculus. About this time Kleene showed that the - calculus was a universal computing system u it was one of the rst such systems to be rigorously analysed 15
17 Enter Computer Science In the 1950s John McCarthy was inspired by the -calculus to invent the programming language LISP In the early 1960s Peter Landin showed how the meaning of imperative programming languages could be specied by translating them into the -calculus u he also invented an inuential prototype programming language called ISWIM u ISWIM introduced the main notations of functional programming u and inuenced the design of both functional and imperative languages u ML was inspired by ISWIM 16
18 Strachey & Turner Building on this work, Christopher Strachey laid the foundations for the important area of denotational semantics Technical questions concerning Strachey's work inspired the mathematical logician Dana Scott to invent the theory of domains u an important part of theoretical computer science During the 1970s Peter Henderson and Jim Morris took up Landin's work and wrote a number of inuential papers arguing that functional programming had important advantages for software engineering At about the same time David Turner proposed that Schonnkel and Curry's combinators could be used as the machine code of computers for eecuting functional programming languages 17
19 Theory can be useful! -calculus is an obscure branch of mathematical logic that underlies important developments in programming language theory, such as the: u study of fundamental questions of computation u design of programming languages u semantics of programming languages u architecture of computers 18
20 Synta and semantics of the -calculus -calculus is a notation for dening functions u each -epression denotes a function u functions can represent data and data-structures u details later u eamples include numbers, pairs, lists Just three kinds of -epressions u Variables u Function applications or Combinations u Abstractions 19
21 Variables Functions denoted by variables are determined by what the variables are bound to u binding is done by abstractions V, V 1, V 2 etc. range over arbitrary variables 20
22 Function applications (combinations) If E 1 and E 2 are -epressions u then so is (E1 E 2 ) u it denotes the result of applying the function denoted by E 1 to the function denoted by E 2 u E 1 is called the rator (from `operator') u E 2 is called the rand (from `operand') 21
23 Abstractions If V is a variable and E is a -epression u then V: E is an abstraction u with bound variable V u and body E Such an abstraction denotes the function that takes an argument a and returns as result the function denoted by E when V denotes a More specically, the abstraction V: E denotes a function which u takes an argument E 0 u and transforms it into E[E 0=V ] u the result of substituting E 0 for V in E u substitution dened later Compare V: E with fn V => E 22
24 Summary of -epressions < -epression> ::= <variable> j j (< -epression> < -epression>) ( <variable> : < -epression>) If V ranges over < variable > And E, E 1, E 2, : : : etc. range over < -epression > Then: E ::= V 6 j (E 1 E 2 ) {z } 6 j V: E {z } 6 variables abstractions applications (combinations) 23
Preface This course aims to teach both the theory and practice of functional programming. The theory consists of the -calculus and the practice will b
Title: Lecturer: Class: Introduction to Functional Programming Mike Gordon (http://www.cl.cam.ac.uk/users/mjcg/) Computer Science Tripos, Part II(General) & Diploma Term: Lent term 1996 First Lecture:
More informationTail Recursion: Factorial. Begin at the beginning. How does it execute? Tail recursion. Tail recursive factorial. Tail recursive factorial
Begin at the beginning Epressions (Synta) Compile-time Static Eec-time Dynamic Types Values (Semantics) 1. Programmer enters epression 2. ML checks if epression is well-typed Using a precise set of rules,
More informationSide note: Tail Recursion. Begin at the beginning. Side note: Tail Recursion. Base Types. Base Type: int. Base Type: int
Begin at the beginning Epressions (Synta) Compile-time Static Eec-time Dynamic Types Values (Semantics) 1. Programmer enters epression 2. ML checks if epression is well-typed Using a precise set of rules,
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 informationProduct types add could take a single argument of the product type int * int fun add(,y):int = +y; > val add = fn : int * int -> int add(3,4); > val i
Lecture 2 0 Product types add could take a single argument of the product type int * int fun add(,y):int = +y; > val add = fn : int * int -> int add(3,4); > val it = 7 : int let val z = (3,4) in add z
More informationLambda Calculus.
Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto, Stephen A. Edwards) Benjamin Pierce Types and Programming Languages http://www.cs.cornell.edu/courses/cs3110/2008fa/recitations/rec26.html
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 informationProgramming Languages
CSE 130 : Fall 2008 Programming Languages Lecture 3: Epressions and Types Ranjit Jhala UC San Diego News PA 1 due (net) Fri 10/10 5pm PA 2 out today or tomorrow Office hours posted on Webpage: Held in
More informationIntroduction to the l-calculus
Introduction to the l-calculus CS345 - Programming Languages Dr. Greg Lavender Department of Computer Sciences The University of Texas at Austin l-calculus in Computer Science a formal notation, theory,
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 informationCMSC 336: Type Systems for Programming Languages Lecture 4: Programming in the Lambda Calculus Acar & Ahmed 22 January 2008.
CMSC 336: Type Systems for Programming Languages Lecture 4: Programming in the Lambda Calculus Acar & Ahmed 22 January 2008 Contents 1 Announcements 1 2 Solution to the Eercise 1 3 Introduction 1 4 Multiple
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 informationPart I. Historical Origins
Introduction to the λ-calculus Part I CS 209 - Functional Programming Dr. Greg Lavender Department of Computer Science Stanford University Historical Origins Foundations of Mathematics (1879-1936) Paradoxes
More informationUntyped Lambda Calculus
Advanced Topics in Programming Languages Untyped Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and Programming
More informationA Quick Overview. CAS 701 Class Presentation 18 November Department of Computing & Software McMaster University. Church s Lambda Calculus
A Quick Overview CAS 701 Class Presentation 18 November 2008 Lambda Department of Computing & Software McMaster University 1.1 Outline 1 2 3 Lambda 4 5 6 7 Type Problem Lambda 1.2 Lambda calculus is a
More informationA Third Look At ML. Chapter Nine Modern Programming Languages, 2nd ed. 1
A Third Look At ML Chapter Nine Modern Programming Languages, 2nd ed. 1 Outline More pattern matching Function values and anonymous functions Higher-order functions and currying Predefined higher-order
More informationCS109A ML Notes for the Week of 1/16/96. Using ML. ML can be used as an interactive language. We. shall use a version running under UNIX, called
CS109A ML Notes for the Week of 1/16/96 Using ML ML can be used as an interactive language. We shall use a version running under UNIX, called SML/NJ or \Standard ML of New Jersey." You can get SML/NJ by
More informationUntyped Lambda Calculus
Concepts in Programming Languages Recitation 5: Untyped Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and
More informationProgramming Languages
CSE 130: Spring 2010 Programming Languages Lecture 3: Epressions and Types Ranjit Jhala UC San Diego A Problem fun -> +1 Can functions only have a single parameter? A Solution: Simultaneous Binding Parameter
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 informationRecap. Recap. If-then-else expressions. If-then-else expressions. If-then-else expressions. If-then-else expressions
Recap Epressions (Synta) Compile-time Static Eec-time Dynamic Types (Semantics) Recap Integers: +,-,* floats: +,-,* Booleans: =,
More informationFunctions as data. Massimo Merro. 9 November Massimo Merro The Lambda language 1 / 21
Functions as data Massimo Merro 9 November 2011 Massimo Merro The Lambda language 1 / 21 The core of sequential programming languages In the mid 1960s, Peter Landin observed that a complex programming
More informationLambda Calculus. CS 550 Programming Languages Jeremy Johnson
Lambda Calculus CS 550 Programming Languages Jeremy Johnson 1 Lambda Calculus The semantics of a pure functional programming language can be mathematically described by a substitution process that mimics
More informationA quick introduction to SML
A quick introduction to SML CMSC 15300 April 9, 2004 1 Introduction Standard ML (SML) is a functional language (or higherorder language) and we will use it in this course to illustrate some of the important
More informationVariables and Bindings
Net: Variables Variables and Bindings Q: How to use variables in ML? Q: How to assign to a variable? # let = 2+2;; val : int = 4 let = e;; Bind the value of epression e to the variable Variables and Bindings
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 informationTypical workflow. CSE341: Programming Languages. Lecture 17 Implementing Languages Including Closures. Reality more complicated
Typical workflow concrete synta (string) "(fn => + ) 4" Parsing CSE341: Programming Languages abstract synta (tree) Lecture 17 Implementing Languages Including Closures Function Constant + 4 Var Var Type
More informationF28PL1 Programming Languages. Lecture 11: Standard ML 1
F28PL1 Programming Languages Lecture 11: Standard ML 1 Imperative languages digital computers are concrete realisations of von Neumann machines stored program memory associations between addresses and
More informationA Brief Introduction to Standard ML
A Brief Introduction to Standard ML Specification and Verification with Higher-Order Logic Arnd Poetzsch-Heffter (Slides by Jens Brandt) Software Technology Group Fachbereich Informatik Technische Universität
More information7. Introduction to Denotational Semantics. Oscar Nierstrasz
7. Introduction to Denotational Semantics Oscar Nierstrasz Roadmap > Syntax and Semantics > Semantics of Expressions > Semantics of Assignment > Other Issues References > D. A. Schmidt, Denotational Semantics,
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 informationA First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1
A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 1 ML Meta Language One of the more popular functional languages (which, admittedly, isn t saying much) Edinburgh, 1974, Robin Milner
More informationCSE341 Section 3. Standard-Library Docs, First-Class Functions, & More
CSE341 Section 3 Standard-Library Docs, First-Class Functions, & More Adapted from slides by Daniel Snitkovskiy, Nick Mooney, Nicholas Shahan, Patrick Larson, and Dan Grossman Agenda 1. SML Docs Standard
More informationMore eamples with half half(0) handle Zero => 1000; > val it = 1000 : int half(1) handle Zero => 1000; > ncaght eception Odd half(0) handle Zero => 10
Lectre 4 0 More eamples with half half(0) handle Zero => 1000; > val it = 1000 : int half(1) handle Zero => 1000; > ncaght eception Odd half(0) handle Zero => 1000 Odd => 1001; > val it = 1000 : int half(3)
More informationLambda Calculus. Concepts in Programming Languages Recitation 6:
Concepts in Programming Languages Recitation 6: Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and Programming
More informationBegin at the beginning
Begin at the beginning Expressions (Syntax) Exec-time Dynamic Values (Semantics) Compile-time Static Types 1. Programmer enters expression 2. ML checks if expression is well-typed Using a precise set of
More informationCSE 341 Section 5. Winter 2018
CSE 341 Section 5 Winter 2018 Midterm Review! Variable Bindings, Shadowing, Let Expressions Boolean, Comparison and Arithmetic Operations Equality Types Types, Datatypes, Type synonyms Tuples, Records
More informationSML A F unctional Functional Language Language Lecture 19
SML A Functional Language Lecture 19 Introduction to SML SML is a functional programming language and acronym for Standard d Meta Language. SML has basic data objects as expressions, functions and list
More information3. Functional Programming. Oscar Nierstrasz
3. Functional Programming Oscar Nierstrasz Roadmap > Functional vs. Imperative Programming > Pattern Matching > Referential Transparency > Lazy Evaluation > Recursion > Higher Order and Curried Functions
More informationCS 242. Fundamentals. Reading: See last slide
CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language
More informationIntroductory Example
CSc 520 Principles of Programming Languages 21: Lambda Calculus Introduction Christian Collberg Department of Computer Science University of Arizona collberg@cs.arizona.edu Copyright c 2005 Christian Collberg
More informationHarvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Tuesday, February 19, 2013 The lambda calculus (or λ-calculus) was introduced by Alonzo Church and Stephen Cole Kleene in
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 informationOCaml. ML Flow. Complex types: Lists. Complex types: Lists. The PL for the discerning hacker. All elements must have same type.
OCaml The PL for the discerning hacker. ML Flow Expressions (Syntax) Compile-time Static 1. Enter expression 2. ML infers a type Exec-time Dynamic Types 3. ML crunches expression down to a value 4. Value
More informationPolymorphism and Type Inference
Polymorphism and Type Inference Volker Stolz stolz@ifi.uio.no Department of Informatics University of Oslo Initially by Gerardo Schneider. Based on John C. Mitchell s slides (Stanford U.) Compile-time
More informationUniversity of Utrecht. 1992; Fokker, 1995), the use of monads to structure functional programs (Wadler,
J. Functional Programming 1 (1): 1{000, January 1993 c 1993 Cambridge University Press 1 F U N C T I O N A L P E A R L S Monadic Parsing in Haskell Graham Hutton University of Nottingham Erik Meijer University
More informationLists. Michael P. Fourman. February 2, 2010
Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a built-in ML type constructor. However, to introduce
More informationLogical Methods in... using Haskell Getting Started
Logical Methods in... using Haskell Getting Started Jan van Eijck May 4, 2005 Abstract The purpose of this course is to teach a bit of functional programming and logic, and to connect logical reasoning
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 informationLambda Calculus see notes on Lambda Calculus
Lambda Calculus see notes on Lambda Calculus Shakil M. Khan adapted from Gunnar Gotshalks recap so far: Lisp data structures basic Lisp programming bound/free variables, scope of variables Lisp symbols,
More informationCSC324- TUTORIAL 5. Shems Saleh* *Some slides inspired by/based on Afsaneh Fazly s slides
CSC324- TUTORIAL 5 ML Shems Saleh* *Some slides inspired by/based on Afsaneh Fazly s slides Assignment 1 2 More questions were added Questions regarding the assignment? Starting ML Who am I? Shems Saleh
More informationHigher Order Functions in Haskell
Higher Order Functions in Haskell Evan Misshula 2018-09-10 Outline Curried Functions Curried comparison Example partial application partial application of a string function Returned functions ZipWith flip
More information1 A question of semantics
PART I BACKGROUND 1 A question of semantics The goal of this chapter is to give the reader a glimpse of the applications and problem areas that have motivated and to this day continue to inspire research
More informationn λxy.x n y, [inc] [add] [mul] [exp] λn.λxy.x(nxy) λmn.m[inc]0 λmn.m([add]n)0 λmn.n([mul]m)1
LAMBDA CALCULUS 1. Background λ-calculus is a formal system with a variety of applications in mathematics, logic, and computer science. It examines the concept of functions as processes, rather than the
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 informationChapter 15 Functional Programming Languages
Chapter 15 Functional Programming Languages Fundamentals of Functional Programming Languages Introduction to Scheme A programming paradigm treats computation as the evaluation of mathematical functions.
More informationLambda Calculus. Gunnar Gotshalks LC-1
Lambda Calculus LC-1 l- Calculus History Developed by Alonzo Church during 1930 s-40 s One fundamental goal was to describe what can be computed. Full definition of l-calculus is equivalent in power to
More informationFunctional Programming
Functional Programming Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. Brief
More informationPure (Untyped) λ-calculus. Andrey Kruglyak, 2010
Pure (Untyped) λ-calculus Andrey Kruglyak, 2010 1 Pure (untyped) λ-calculus An example of a simple formal language Invented by Alonzo Church (1936) Used as a core language (a calculus capturing the essential
More informationCSci 4223 Principles of Programming Languages
CSci 4223 Principles of Programming Languages Lecture 11 Review Features learned: functions, tuples, lists, let expressions, options, records, datatypes, case expressions, type synonyms, pattern matching,
More informationNews. CSE 130: Programming Languages. Environments & Closures. Functions are first-class values. Recap: Functions as first-class values
CSE 130: Programming Languages Environments & Closures News PA 3 due THIS Friday (5/1) Midterm NEXT Friday (5/8) Ranjit Jhala UC San Diego Recap: Functions as first-class values Arguments, return values,
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 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 Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional
More informationLecture 5: The Untyped λ-calculus
Lecture 5: The Untyped λ-calculus Syntax and basic examples Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Static Analysis Pratikakis (CSD) Untyped λ-calculus I CS49040,
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 informationLecture 3: Recursion; Structural Induction
15-150 Lecture 3: Recursion; Structural Induction Lecture by Dan Licata January 24, 2012 Today, we are going to talk about one of the most important ideas in functional programming, structural recursion
More informationChristopher Strachey and the Development of CPL. by Martin Richards
Christopher Strachey and the Development of CPL by Martin Richards www.cl.cam.ac.uk/users/mr10 The CPL Project The CPL Project ran from about 1962 to the end of 1966. I was involved as a Research Student
More informationLast class. CS Principles of Programming Languages. Introduction. Outline
Last class CS6848 - Principles of Programming Languages Principles of Programming Languages V. Krishna Nandivada IIT Madras Interpreters A Environment B Cells C Closures D Recursive environments E Interpreting
More informationProgramming Systems in Artificial Intelligence Functional Programming
Click to add Text Programming Systems in Artificial Intelligence Functional Programming Siegfried Nijssen 8/03/16 Discover thediscover world at the Leiden world University at Leiden University Overview
More informationNews. Programming Languages. Complex types: Lists. Recap: ML s Holy Trinity. CSE 130: Spring 2012
News CSE 130: Spring 2012 Programming Languages On webpage: Suggested HW #1 PA #1 (due next Fri 4/13) Lecture 2: A Crash Course in ML Please post questions to Piazza Ranjit Jhala UC San Diego Today: A
More informationVU Semantik von Programmiersprachen
VU Semantik von Programmiersprachen Agata Ciabattoni Institute für Computersprachen, Theory and Logic group (agata@logic.at) (A gentle) Introduction to λ calculus p. 1 Why shoud I studyλcalculus? p. 2
More informationMore Lambda Calculus and Intro to Type Systems
More Lambda Calculus and Intro to Type Systems Plan Heavy Class Participation Thus, wake up! Lambda Calculus How is it related to real life? Encodings Fixed points Type Systems Overview Static, Dyamic
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 informationProgramming Languages Third Edition
Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand
More informationA notation for describing computations that focuses. Allows convenient denition and manipulation of
Introduction to -calculus A notation for describing computations that focuses on function denition and application. Allows convenient denition and manipulation of functions as \rst-class" values. Eample:
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 informationRecursion. Tjark Weber. Functional Programming 1. Based on notes by Sven-Olof Nyström. Tjark Weber (UU) Recursion 1 / 37
Tjark Weber Functional Programming 1 Based on notes by Sven-Olof Nyström Tjark Weber (UU) Recursion 1 / 37 Background FP I / Advanced FP FP I / Advanced FP This course (Functional Programming I) (5 hp,
More informationCom S 541. Programming Languages I
Programming Languages I Lecturer: TA: Markus Lumpe Department of Computer Science 113 Atanasoff Hall http://www.cs.iastate.edu/~lumpe/coms541.html TR 12:40-2, W 5 Pramod Bhanu Rama Rao Office hours: TR
More informationChapter 15. Functional Programming Languages
Chapter 15 Functional Programming Languages Copyright 2009 Addison-Wesley. All rights reserved. 1-2 Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages
More informationLecture 13 CIS 341: COMPILERS
Lecture 13 CIS 341: COMPILERS Announcements HW4: OAT v. 1.0 Parsing & basic code generation Due: March 28 th START EARLY! Midterm Exam Grades Available on Gradescope Zdancewic CIS 341: Compilers 2 Midterm
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 informationA list is a finite sequence of elements. Elements may appear more than once
Standard ML Lists ML Lists.1 Lists A list is a finite sequence of elements. [3,5,9] ["a", "list" ] [] Elements may appear more than once [3,4] [4,3] [3,4,3] [3,3,4] Elements may have any type. But all
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 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 informationCPS 506 Comparative Programming Languages. Programming Language Paradigm
CPS 506 Comparative Programming Languages Functional Programming Language Paradigm Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming
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 informationStandard ML. Curried Functions. ML Curried Functions.1
Standard ML Curried Functions ML Curried Functions.1 Curried Functions Side Note: Infix function declaration o Curried Function declaration o Declaring via "fun" o Function Calling Order o Examples o Mixing
More information1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.
1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered
More informationCSE341: Programming Languages Lecture 9 Function-Closure Idioms. Dan Grossman Winter 2013
CSE341: Programming Languages Lecture 9 Function-Closure Idioms Dan Grossman Winter 2013 More idioms We know the rule for lexical scope and function closures Now what is it good for A partial but wide-ranging
More informationMore Lambda Calculus and Intro to Type Systems
More Lambda Calculus and Intro to Type Systems #1 One Slide Summary The lambda calculus is a model of computation or a programming language that is as expressive as a Turing machine. The lambda calculus
More informationCMSC 330: Organization of Programming Languages. Functional Programming with Lists
CMSC 330: Organization of Programming Languages Functional Programming with Lists CMSC330 Spring 2018 1 Lists in OCaml The basic data structure in OCaml Lists can be of arbitrary length Implemented as
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 informationHaskell 98 in short! CPSC 449 Principles of Programming Languages
Haskell 98 in short! n Syntax and type inferencing similar to ML! n Strongly typed! n Allows for pattern matching in definitions! n Uses lazy evaluation" F definition of infinite lists possible! n Has
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 informationAs Natural as 0, 1, 2. Philip Wadler University of Edinburgh
As Natural as 0, 1, 2 Philip Wadler University of Edinburgh wadler@inf.ed.ac.uk Haskell Hindley-Milner types Java Girard-Reynolds types XML Operational semantics Part 0 Counting starts at zero Carle Carle
More informationProgramming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine.
CMSC 330: Organization of Programming Languages Lambda Calculus Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Ø Use currying or tuples
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 informationExercises on ML. Programming Languages. Chanseok Oh
Exercises on ML Programming Languages Chanseok Oh chanseok@cs.nyu.edu Dejected by an arcane type error? - foldr; val it = fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b - foldr (fn x=> fn y => fn z => (max
More information02157 Functional Programming. Michael R. Ha. Lecture 1: Introduction and Getting Started. Michael R. Hansen
Lecture 1: Introduction and Getting Started nsen 1 DTU Compute, Technical University of Denmark Lecture 1: Introduction and Getting Started MRH 06/09/2018 WELCOME to Teacher: nsen, DTU Compute mire@dtu.dk
More information