Thoughts on Assignment 4 Haskell: Flow of Control

Size: px
Start display at page:

Download "Thoughts on Assignment 4 Haskell: Flow of Control"

Transcription

1 Thoughts on Assignment 4 Haskell: Flow of Control CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 27, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu 2017 Glenn G. Chappell

2 Thoughts on Assignment 4 Introduction In Assignment 4 you will be writing a Recursive-Descent parser, in the form of Lua module parseit. It will be similar to module rdparser4 (written in class), but it will involve a different grammar & AST specification. In Assignment 6 you will write an interpreter that takes, as input, an AST of the form your parser returns. The result will be an implementation of a programming language called Kanchil. Module parseit is to parse a complete programming language, while module rdparser4 only parses expressions. Nonetheless, Kanchil has expressions, and they work in much the same way as those handled by rdparser4. I suggest using file rdparser4.lua as a starting point for Assignment Feb 2017 CS F331 / CSCE A331 Spring

3 Thoughts on Assignment 4 The Goal Again, here is a sample Kanchil program. # Subroutine &fibo # Given %k, set %fibk to F(%k), # where F(n) = nth Fibonacci no. sub &fibo set %a: 0 # Consecutive Fibos set %b: 1 set %i: 0 # Loop counter while %i < %k set %c: %a+%b # Advance set %a: %b set %b: %c set %i: %i+1 # ++counter end set %fibk: %a # Result end # Get number of Fibos to output print "How many Fibos to print: " input %n cr # Print requested number of Fibos set %j: 0 # Loop counter while %j < %n set %k: %j call &fibo print "F(" print %j print ") = " print %fibk cr set %j: %j + 1 end 27 Feb 2017 CS F331 / CSCE A331 Spring

4 Thoughts on Assignment 4 The Grammar (1) program stmt_list (2) stmt_list { statement } (3) statement cr (4) print ( STRLIT expr ) (5) input lvalue (6) set lvalue : expr (7) sub SUBID stmt_list end (8) call SUBID (9) if expr stmt_list { elseif expr stmt_list } [ else stmt_list ] end (10) while expr stmt_list end (11) expr comp_expr { ( && ) comp_expr } (12) comp_expr! comp_expr (13) arith_expr { ( ==!= < <= > >= ) arith_expr } (14) arith_expr term { ( + - ) term } (15) term factor { ( * / % ) factor } (16) factor ( + - ) factor (17) ( expr ) (18) NUMLIT (19) ( true false ) (20) lvalue (21) lvalue VARID [ [ expr ] ] 27 Feb 2017 CS F331 / CSCE A331 Spring

5 Thoughts on Assignment 4 Calling lexit.preferop Your parser will need to call function lexit.preferop immediately after it sees a lexeme that fits any of the following. category == VARID category == NUMLIT string == "]" string == ")" string == "true" string == "false" I suggest that you handle this in function advance. Then this issue does not have to be dealt with in your parsing functions at all. You can write it once, and never worry about it again. 27 Feb 2017 CS F331 / CSCE A331 Spring

6 Thoughts on Assignment 4 Returning Two Values The most common mistake I made when writing module parseit was to return only one value from a parsing function. Remember that a parsing function will always return two values: boolean & AST. If the boolean is True, then the AST needs to be in the proper form. If the boolean is False, then the AST can be anything (it might as well be nil). 27 Feb 2017 CS F331 / CSCE A331 Spring

7 Thoughts on Assignment 4 Parsing end Three kinds of Kanchil statements are terminated with an end keyword: Sub statements (subroutine definitions) If statements While statements (while loops) Other kinds of statements have no end. This means, for example, that you generally do not want to exit the parsing function early if you think the if-statement is over. So code like the following is not good. if not matchstring("else") then end return true, ast 27 Feb 2017 CS F331 / CSCE A331 Spring

8 Thoughts on Assignment 4 Some Code I have posted a file containing a portion of my version of parseit.lua. See assn4_code.txt. 27 Feb 2017 CS F331 / CSCE A331 Spring

9 Review PL Categories: Functional PLs Functional programming (FP) is a programming style in which functions are primary, and side effects & mutable data are avoided. A functional programming language is a PL designed to support FP well. A pure functional PL does not support mutable data at all. 27 Feb 2017 CS F331 / CSCE A331 Spring

10 Review Introduction to Haskell Haskell is a pure functional PL. It has first-class functions and good support for higher-order functions. Haskell has a sound static type system with sophisticated type inference. Typing is largely inferred, and thus implicit; however, type annotations are permitted. Haskell has no iteration. Recursion is used. Tail-call optimization (TCO) is done. Haskell has significant indentation. Evaluation in Haskell is lazy. 27 Feb 2017 CS F331 / CSCE A331 Spring

11 Review Haskell: Functions [1/2] Function definition: what looks like a function call, an equals sign, and an expression for the value of the function. Pattern matching is used. Introduce local definitions with where. Patterns factorial 0 = 1 factorial n = n * factorial prev prev = n-1 Local definition where We can also define new infix binary operators. a +$+ b = 2*a + b 27 Feb 2017 CS F331 / CSCE A331 Spring

12 Review Haskell: Functions [2/2] Currying: simulating a multiparameter function using a single parameter function that returns a function. sub a b = a-b sub Returns 3 sub_from_5 = sub 5 sub_from_ Returns 3 Currying makes some higher-order functions easy to write. rev f a b = f b a rsub = rev sub rsub Returns -3 rsub Returns 3 27 Feb 2017 CS F331 / CSCE A331 Spring

13 Review Haskell: Lists Lists & Tuples [1/2] A statically typed PL will typically support two ways of aggregating multiple data items into a single collection: A collection of an arbitrary number of data items, all of the same type. Example. C++ vector, list, deque. A collection of a fixed number of data items, possibly of different types. Example. C++ tuple, struct. Haskell supports the above two categories as well, in the form of lists and tuples. A Haskell tuple holds a fixed number of data items, possibly of different types. > :t (2.1, 1.2, True) (Double,Double,Bool) This represents the GHCi prompt. For code, see list.hs. 27 Feb 2017 CS F331 / CSCE A331 Spring

14 Review Haskell: Lists Lists & Tuples [2/2] A Haskell list holds an arbitrary number of data items, all of the same type. A list literal uses brackets and commas. ["hello", "there"] -- List of two String values [[1], [], [1,2,3,4]] -- List of lists of Integer [1, [2, 3]] -- ERROR; types differ [1, 3..] -- Infinite list The type of a list is written as the item type in brackets. > :t [True, False] [True, False] :: [Bool] > :t [False, True, True, True, True, False] [False, True, True, True, True, False] :: [Bool] 27 Feb 2017 CS F331 / CSCE A331 Spring

15 Review Haskell: Lists List Primitives 1. Construct an empty list. [] 2. Cons: list from first item, list of other items. Uses colon (:). 5:[2, 1, 8] -- Same as [5, 2, 1, 8] 5:2:1:8:[] -- Also same; ":" is right-associative 3. Pattern matching for lists. ff [] = 3 -- Value of ff for an empty list ff (x:xs) = 4 -- Value of ff for a nonempty list gg [a, b, c] = Value of gg for a 3-item list 27 Feb 2017 CS F331 / CSCE A331 Spring

16 Review Haskell: Lists Other List Syntax: Strings & Ranges A Haskell String is a list of characters (Char values). ['a', 'b', 'c'] "abc" -- Same as above Use.. to construct a list holding a range of values. There are exactly four ways to do this. [1..10] -- Same as [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] [1,3..10] -- Same as [1, 3, 5, 7, 9] [1..] -- Infinite list: [1, 2, 3, 4, 5, 6, 7, 8, ] [1,3..] -- Infinite list: [1, 3, 5, 7, 9, 11, ] These four are wrappers around enumfromto, enumfromthento, enumfrom, and enumfromthen, respectively. 27 Feb 2017 CS F331 / CSCE A331 Spring

17 Review Haskell: Lists Other List Syntax: List Comprehensions [1/2] You have probably seen the mathematical notation known as a set comprehension (or set-builder notation). Here is an example. { xy x {3, 2, 1} and y {10, 11, 12} } The above is read as, The set of all xy for x in the set {1, 2, 3} and y in the set {10, 11, 12}. A number of PLs, including Haskell, have a construct based on this idea: the list comprehension. Here is a Haskell example. [ x*y x <- [3, 2, 1], y <- [10, 11, 12] ] This deals with Haskell lists instead of sets, but is otherwise very similar to the above set comprehension. 27 Feb 2017 CS F331 / CSCE A331 Spring

18 Review Haskell: Lists Other List Syntax: List Comprehensions [2/2] The syntax of a Haskell list comprehension is as follows. Brackets enclose the following: An expression. Then a vertical bar ( ). Then a comma-separated list of two kinds of things: var <- list Expression of type Bool Here are some examples: > [ x*y x <- [3, 2, 1], y <- [10, 11, 12] ] [30,33,36,20,22,24,10,11,12] > [ x*x x <- [1..6] ] [1,4,9,16,25,36] > [ x x <- [1..20], x `mod` 2 == 1] [1,3,5,7,9,11,13,15,17,19] 27 Feb 2017 CS F331 / CSCE A331 Spring

19 Review Haskell: Lists Lists & Recursion [1/3] When writing a function that takes a list, it is very common to have two cases. One case handles the empty list: []. The other case handles nonempty lists. Remember that a pattern like a:as matches nonempty lists. isempty [] = True isempty (x:xs) = False listlength [] = 0 listlength (x:xs) = 1 + listlength xs 27 Feb 2017 CS F331 / CSCE A331 Spring

20 Review Haskell: Lists Lists & Recursion [2/3] A function that takes a list will often be recursive. Such a function will usually be organized as follows. The version that handles the empty list ([]) will be the base case. The version that handles nonempty lists (b:bs) will be the recursive case. This will do a computation involving the head of the list (b) and make a recursive call with the tail (bs). myfilter p [] = [] -- p for predicate: function -- returning Bool myfilter p (x:xs) = if (p x) then x:rest else rest where rest = myfilter p xs Note the if then else construction. We can put line breaks pretty much anywhere we want inside this construction. 27 Feb 2017 CS F331 / CSCE A331 Spring

21 Review Haskell: Lists Lists & Recursion [3/3] Sometimes other kinds of recursion are used. Here is a function that does lookup by index in a list (zero-based). lookup 0 (x:xs) = x lookup n (x:xs) = lookup (n-1) xs lookup _ [] = error "lookup: index too big or negative" This pattern means unused parameter. Function error takes a String and returns any type; that is, it can be used in any context. It does not actually return anything. Instead, it crashes the program, printing a message that includes the given String. An alternate error-message function is undefined, which takes no parameters. It is like error with a default message. lookup _ [] = undefined -- Replaces the above line 27 Feb 2017 CS F331 / CSCE A331 Spring

22 Haskell: Flow of Control Introduction Flow of control refers to the ways a PL determines what code is executed. For example, flow of control in Lua includes: Selection (if elseif else). Iteration (while, for). Function calls. Coroutines. Threads. Exceptions. Haskell has very different flow-of-control facilities from most imperative PLs. Key Idea. Things that are done with traditional flow-of-control constructs in imperative programming languages are often done differently in Haskell. For code, see flow.hs. 27 Feb 2017 CS F331 / CSCE A331 Spring

23 Haskell: Flow of Control Pattern Matching, Recursion, Lazy Evaluation [1/5] We have seen that Haskell has a useful pattern matching facility, which allows us to choose one of a number of function definitions. The rule is that the first definition with a matching pattern is the one used. isempty [] = True isempty (x:xs) = False -- fibo the SLOW way fibo 0 = 0 fibo 1 = 1 fibo n = fibo (n-2) + fibo (n-1) In many of the places we would use an if else construction in an imperative PL, we use pattern matching in Haskell. 27 Feb 2017 CS F331 / CSCE A331 Spring

24 Haskell: Flow of Control Pattern Matching, Recursion, Lazy Evaluation [2/5] Haskell also makes heavy use of recursion. Recursion can be less costly in Haskell than in PLs like C++, because of Haskell s required tail-call optimization (TCO). TCO means that a tail call does not use additional stack space. listlength [] = 0 listlength (x:xs) = 1 + listlength xs In places where we would use a loop in an imperative PL, we use recursion in Haskell. 27 Feb 2017 CS F331 / CSCE A331 Spring

25 Haskell: Flow of Control Pattern Matching, Recursion, Lazy Evaluation [3/5] By default, Haskell does lazy evaluation. This allows for infinite lists. We have said that we can generate these even without the.. syntax. But how? Here is an idea. -- listfrom n -- Returns the infinite list [n, n+1, n+2, ]. listfrom n = n:listfrom (n+1) Is this code acceptable? It has recursion without a base case. But this is not a problem, thanks to lazy evaluation. A recursive call is only made if further list items are needed. Using only a finite number of items guarantees that the recursion terminates. The above code uses corecursion: A stream of values is generated recursively. The recursion terminates when no more values are needed. 27 Feb 2017 CS F331 / CSCE A331 Spring

26 Haskell: Flow of Control Pattern Matching, Recursion, Lazy Evaluation [4/5] Something else we can do: write our own if else, as a function. -- myif condition tval fval -- Returns tval if condition is True, fval otherwise. myif True tval _ = tval myif False _ fval = fval Note that no more than one of tval, fval is ever evaluated, thanks to lazy evaluation. Here is the slow Fibonacci algorithm using myif. fibo n = myif (n <= 1) n (fibo (n-2) + fibo (n-1)) 27 Feb 2017 CS F331 / CSCE A331 Spring

27 Haskell: Flow of Control Pattern Matching, Recursion, Lazy Evaluation [5/5] And here is myfilter, reimplemented using myif. myfilter p [] = [] myfilter p (x:xs) = myif (p x) (x:rest) rest where rest = myfilter p xs It turns out that the combination of pattern matching, recursion, and lazy evaluation, together with function calls, are all we need. We can build any flow-of-control construct out of these. However, Haskell has other flow-of-control facilities, for convenience. Next we look at a few of these. 27 Feb 2017 CS F331 / CSCE A331 Spring

28 Haskell: Flow of Control Selection Introduction Selection allows us to choose one of multiple options to execute. Selection in C++ includes if else, switch, and virtual function dispatch. In Haskell, pattern matching works as a selection mechanism. Other selection constructions include guards, if then else, and case. 27 Feb 2017 CS F331 / CSCE A331 Spring

29 Haskell: Flow of Control Selection Guards [1/3] Guards are the Haskell equivalent of mathematical notation like the following. x, if x 0; myabs x = ( x, otherwise. In Haskell: myabs x x >= 0 = x otherwise = -x We use guards in situations that pattern matching cannot handle. For example, there is no pattern that matches only nonnegative numbers. 27 Feb 2017 CS F331 / CSCE A331 Spring

30 Haskell: Flow of Control Selection Guards [2/3] myabs x x >= 0 = x otherwise = -x Note that there is no equals sign after the first line above. Each vertical bar is followed by a boolean expression. The first True expression tells which value is used. We generally want the last line to handle all remaining cases. We could use True as our final expression. otherwise is a variable with value True. Here is the slow Fibonacci algorithm reimplemented using guards. fibo n n <= 1 = n otherwise = fibo (n-2) + fibo (n-1) 27 Feb 2017 CS F331 / CSCE A331 Spring

31 Haskell: Flow of Control Selection Guards [3/3] Here is myfilter reimplemented using guards. myfilter p [] = [] myfilter p (x:xs) p x = x:rest otherwise = rest where rest = myfilter p xs 27 Feb 2017 CS F331 / CSCE A331 Spring

32 Haskell: Flow of Control Selection if then else We have seen Haskell s if then else construction. This is much like our myif. myif condition tval fval if condition then tval else fval -- Same as above Most of the possible uses of if then else are probably better done with guards. And some people consider if then else to be un-haskell-ish. But use it if you want. 27 Feb 2017 CS F331 / CSCE A331 Spring

33 Haskell: Flow of Control Selection case Haskell s case construction is analogous to switch in C++. Here is an example, using case and using multiple function definitions. -- case fibo n = case n of 0 -> 0 1 -> 1 _ -> fibo (n-2) + fibo (n-1) -- Multiple definitions fibo 0 = 0 fibo 1 = 1 fibo n = fibo (n-2) + fibo (n-1) A case construction can always be replaced by multiple definitions. So I never use case. But case does have an important behind-thescenes role. Multiple definitions are actually syntactic sugar over a case construction. 27 Feb 2017 CS F331 / CSCE A331 Spring

34 Haskell: Flow of Control Error Handling Fatal Errors We have seen Haskell s fatal-error facilities: error and undefined. lookup 0 (x:xs) = x lookup n (x:xs) = lookup (n-1) xs lookup _ [] = error "lookup: index too big or negative" These should be reserved for cases when a program needs to crash. This is generally because the program has detected a bug in its code. It crashes with an explanatory message, so that a developer can fix the bug. 27 Feb 2017 CS F331 / CSCE A331 Spring

35 Haskell: Flow of Control Error Handling Exceptions Haskell also has an exception mechanism, for dealing with error conditions that may be handled at runtime. I think that Haskell s exceptions are best avoided by new Haskell programmers (and many experienced Haskell programmers). So we will not be covering them. If you look into Haskell s exceptions, be aware that the terms error and exception are used inconsistently in both the standard library naming conventions and its documentation. Some documentation authors have difficulty explaining the difference between the two terms; others seem unaware that there is a difference. 27 Feb 2017 CS F331 / CSCE A331 Spring

36 Haskell: Flow of Control Error Handling Implementing Exceptions [1/6] As with other Haskell features, it can be interesting to see how we might implement something like exceptions ourselves. We can do a rudimentary exception implementation using maybe types. Suppose t is a Haskell type. The type Maybe t has two kinds of values: Just x, where x is a value of type t, and Nothing. We can distinguish between these using pattern matching. squaremaybe (Just x) = Just (x*x) squaremaybe Nothing = Nothing Just and Nothing are examples of Haskell constructors. 27 Feb 2017 CS F331 / CSCE A331 Spring

37 Haskell: Flow of Control Error Handling Implementing Exceptions [2/6] Suppose we use Just x to represent the value x and Nothing to represent an exception. esqrt :: Double -> Maybe Double esqrt x x < 0.0 = Nothing otherwise = Just (sqrt x) It would probably be better if our function took the same kind of value that it returns 27 Feb 2017 CS F331 / CSCE A331 Spring

38 Haskell: Flow of Control Error Handling Implementing Exceptions [3/6] It would probably be better if our function took the same kind of value that it returns. esqrt :: Maybe Double -> Maybe Double esqrt Nothing = Nothing esqrt (Just x) x < 0.0 = Nothing otherwise = Just (sqrt x) Now the function not only raises exceptions; it also propagates exceptions it receives to its caller. (This is analogous to what is called exception neutrality in C++.) 27 Feb 2017 CS F331 / CSCE A331 Spring

39 Haskell: Flow of Control Error Handling Implementing Exceptions [4/6] Here is a division operator that uses this idea. (I since / is already taken.) infixl -- Sets precedence, left associativity (@/) :: Maybe Double -> Maybe Double -> Maybe Double _ = Nothing Nothing = Nothing (Just (Just 0.0) = Nothing (Just (Just y) = Just (x / y) 27 Feb 2017 CS F331 / CSCE A331 Spring

40 Haskell: Flow of Control Error Handling Implementing Exceptions [5/6] We can write other operators this way. A few conveniences: e1 = Just 1.0 e2 = Just 2.0 e3 = Just 3.0 printit (Just x) = show x printit Nothing = "ERROR!" Conversion to String Examples: Function application, but very low precedence > printit $ e2 0.5 > printit $ e2) * e2 "ERROR!" 27 Feb 2017 CS F331 / CSCE A331 Spring

41 Haskell: Flow of Control Error Handling Implementing Exceptions [6/6] We could improve this arithmetic package just a bit. Using type classes, we can overload the / operator, and thus avoid We can also overload the show function, so that our values can be printed in the usual way. There might be an objection to my referring to the error signals used by this package as exceptions. They are normal return values. Why call them exceptions? My answer is that, because of the way the various functions & operators are written, error signals propagate automatically to the caller. Once an error has been found, no more arithmetic is done (because of lazy evaluation, no more arithmetic at all); the error signal is simply sent to the caller. While this mechanism may not be exceptions in some precise sense, it acts enough like exceptions as we know them, to warrant the name (I think). 27 Feb 2017 CS F331 / CSCE A331 Spring

42 Haskell: Flow of Control TO BE CONTINUED Haskell: Flow of Control will be continued next time. 27 Feb 2017 CS F331 / CSCE A331 Spring

Haskell: 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, 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 information

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G. Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu

More information

Writing an Interpreter Thoughts on Assignment 6

Writing an Interpreter Thoughts on Assignment 6 Writing an Interpreter Thoughts on Assignment 6 CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, March 27, 2017 Glenn G. Chappell Department of Computer Science

More information

Writing a Lexer. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 6, Glenn G.

Writing a Lexer. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 6, Glenn G. Writing a Lexer CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 6, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks

More information

PL Categories: Functional PLs Introduction to Haskell Haskell: Functions

PL Categories: Functional PLs Introduction to Haskell Haskell: Functions PL Categories: Functional PLs Introduction to Haskell Haskell: Functions CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Wednesday, February 22, 2017 Glenn G. Chappell

More information

Scheme: Expressions & Procedures

Scheme: Expressions & Procedures Scheme: Expressions & Procedures CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, March 31, 2017 Glenn G. Chappell Department of Computer Science University

More information

Introduction to Syntax Analysis Recursive-Descent Parsing

Introduction to Syntax Analysis Recursive-Descent Parsing Introduction to Syntax Analysis Recursive-Descent Parsing CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 10, 2017 Glenn G. Chappell Department of

More information

CS 11 Haskell track: lecture 1

CS 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 information

Lecture 19: Functions, Types and Data Structures in Haskell

Lecture 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 information

CS 360: Programming Languages Lecture 10: Introduction to Haskell

CS 360: Programming Languages Lecture 10: Introduction to Haskell CS 360: Programming Languages Lecture 10: Introduction to Haskell Geoffrey Mainland Drexel University Thursday, February 5, 2015 Adapted from Brent Yorgey s course Introduction to Haskell. Section 1 Administrivia

More information

n n Try tutorial on front page to get started! n spring13/ n Stack Overflow!

n   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 information

Scheme: Strings Scheme: I/O

Scheme: Strings Scheme: I/O Scheme: Strings Scheme: I/O CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Wednesday, April 5, 2017 Glenn G. Chappell Department of Computer Science University of

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

More information

It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis

It 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 information

Haskell Introduction Lists Other Structures Data Structures. Haskell Introduction. Mark Snyder

Haskell 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 information

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSC312 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 information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 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 information

CS 320: Concepts of Programming Languages

CS 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 information

SML A F unctional Functional Language Language Lecture 19

SML 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 information

The List Datatype. CSc 372. Comparative Programming Languages. 6 : Haskell Lists. Department of Computer Science University of Arizona

The List Datatype. CSc 372. Comparative Programming Languages. 6 : Haskell Lists. Department of Computer Science University of Arizona The List Datatype CSc 372 Comparative Programming Languages 6 : Haskell Lists Department of Computer Science University of Arizona collberg@gmail.com All functional programming languages have the ConsList

More information

Types and Static Type Checking (Introducing Micro-Haskell)

Types and Static Type Checking (Introducing Micro-Haskell) Types and Static (Introducing Micro-Haskell) Informatics 2A: Lecture 13 Alex Simpson School of Informatics University of Edinburgh als@inf.ed.ac.uk 16 October, 2012 1 / 21 1 Types 2 3 4 2 / 21 Thus far

More information

This example highlights the difference between imperative and functional programming. The imperative programming solution is based on an accumulator

This example highlights the difference between imperative and functional programming. The imperative programming solution is based on an accumulator 1 2 This example highlights the difference between imperative and functional programming. The imperative programming solution is based on an accumulator (total) and a counter (i); it works by assigning

More information

Programming Paradigms

Programming Paradigms PP 2017/18 Unit 11 Functional Programming with Haskell 1/37 Programming Paradigms Unit 11 Functional Programming with Haskell J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE

More information

A 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 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 information

Programming Languages Fall 2013

Programming 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 information

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

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 18 Thursday, March 29, 2018 In abstract algebra, algebraic structures are defined by a set of elements and operations

More information

CS 360: Programming Languages Lecture 12: More Haskell

CS 360: Programming Languages Lecture 12: More Haskell CS 360: Programming Languages Lecture 12: More Haskell Geoffrey Mainland Drexel University Adapted from Brent Yorgey s course Introduction to Haskell. Section 1 Administrivia Administrivia Homework 5 due

More information

CS 320: Concepts of Programming Languages

CS 320: Concepts of Programming Languages CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 08: Type Classes o o Review: What is a type class? Basic Type Classes: Eq, Ord, Enum, Integral,

More information

A general introduction to Functional Programming using Haskell

A general introduction to Functional Programming using Haskell A general introduction to Functional Programming using Haskell Matteo Rossi Dipartimento di Elettronica e Informazione Politecnico di Milano rossi@elet.polimi.it 1 Functional programming in a nutshell

More information

Parsing Combinators: Introduction & Tutorial

Parsing Combinators: Introduction & Tutorial Parsing Combinators: Introduction & Tutorial Mayer Goldberg October 21, 2017 Contents 1 Synopsis 1 2 Backus-Naur Form (BNF) 2 3 Parsing Combinators 3 4 Simple constructors 4 5 The parser stack 6 6 Recursive

More information

Lists. Michael P. Fourman. February 2, 2010

Lists. 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 information

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0))

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0)) SCHEME 0 COMPUTER SCIENCE 6A July 26, 206 0. Warm Up: Conditional Expressions. What does Scheme print? scm> (if (or #t (/ 0 (/ 0 scm> (if (> 4 3 (+ 2 3 4 (+ 3 4 (* 3 2 scm> ((if (< 4 3 + - 4 00 scm> (if

More information

Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions

Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions Greg Plaxton Theory in Programming Practice, Spring 2005 Department of Computer Science University of Texas at Austin

More information

CSE 3302 Programming Languages Lecture 8: Functional Programming

CSE 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 information

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Functional Programming and Haskell

Functional 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 information

CSCI-GA Scripting Languages

CSCI-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 information

PROGRAMMING IN HASKELL. Chapter 2 - First Steps

PROGRAMMING IN HASKELL. Chapter 2 - First Steps PROGRAMMING IN HASKELL Chapter 2 - First Steps 0 The Hugs System Hugs is an implementation of Haskell 98, and is the most widely used Haskell system; The interactive nature of Hugs makes it well suited

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

EECS 700 Functional Programming

EECS 700 Functional Programming EECS 700 Functional Programming Dr. Andy Gill University of Kansas February 16, 2010 1 / 41 Parsing A parser is a program that analyses a piece of text to determine its syntactic structure. The expression

More information

Solution sheet 1. Introduction. Exercise 1 - Types of values. Exercise 2 - Constructors

Solution sheet 1. Introduction. Exercise 1 - Types of values. Exercise 2 - Constructors Solution sheet 1 Introduction Please note that there can be other solutions than those listed in this document. This is a literate Haskell file which is available as PDF, as well as literate Haskell source

More information

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE

More information

INTRODUCTION TO HASKELL

INTRODUCTION TO HASKELL INTRODUCTION TO HASKELL PRINCIPLES OF PROGRAMMING LANGUAGES Norbert Zeh Winter 2018 Dalhousie University 1/81 HASKELL: A PURELY FUNCTIONAL PROGRAMMING LANGUAGE Functions are first-class values: Can be

More information

Haske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell

Haske 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 information

Logic - CM0845 Introduction to Haskell

Logic - 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 information

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

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Functions 1 CSCE 314: Programming Languages Dr. Flemming Andersen Haskell Functions 2 Outline Defining Functions List Comprehensions Recursion 3 Conditional Expressions As in most programming languages, functions

More information

Example Scheme Function: equal

Example Scheme Function: equal ICOM 4036 Programming Languages Functional Programming Languages Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language: LISP Introduction to

More information

Functional Programming Languages (FPL)

Functional 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 information

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS 1 THE FORMALIZATION OF MATHEMATICS by Harvey M. Friedman Ohio State University Department of Mathematics friedman@math.ohio-state.edu www.math.ohio-state.edu/~friedman/ May 21, 1997 Can mathematics be

More information

COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml

COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml COSE212: Programming Languages Lecture 3 Functional Programming in OCaml Hakjoo Oh 2017 Fall Hakjoo Oh COSE212 2017 Fall, Lecture 3 September 18, 2017 1 / 44 Why learn ML? Learning ML is a good way of

More information

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program: Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams

More information

Functional Programming for Logicians - Lecture 1

Functional Programming for Logicians - Lecture 1 Functional Programming for Logicians - Lecture 1 Functions, Lists, Types Malvin Gattinger 4 June 2018 module L1 where Introduction Who is who Course website: https://malv.in/2018/funcproglog/ Malvin Gattinger

More information

An introduction introduction to functional functional programming programming using usin Haskell

An 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 information

CSCC24 Functional Programming Scheme Part 2

CSCC24 Functional Programming Scheme Part 2 CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisp-like Languages

More information

Parsing. Zhenjiang Hu. May 31, June 7, June 14, All Right Reserved. National Institute of Informatics

Parsing. Zhenjiang Hu. May 31, June 7, June 14, All Right Reserved. National Institute of Informatics National Institute of Informatics May 31, June 7, June 14, 2010 All Right Reserved. Outline I 1 Parser Type 2 Monad Parser Monad 3 Derived Primitives 4 5 6 Outline Parser Type 1 Parser Type 2 3 4 5 6 What

More information

Syntax and Grammars 1 / 21

Syntax and Grammars 1 / 21 Syntax and Grammars 1 / 21 Outline What is a language? Abstract syntax and grammars Abstract syntax vs. concrete syntax Encoding grammars as Haskell data types What is a language? 2 / 21 What is a language?

More information

Haskell through HUGS THE BASICS

Haskell through HUGS THE BASICS Haskell through HUGS THE BASICS FP for DB Basic HUGS 1 Algorithmic Imperative Languages variables assignment if condition then action1 else action2 loop block while condition do action repeat action until

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

CSCE 314 Programming Languages. Functional Parsers

CSCE 314 Programming Languages. Functional Parsers CSCE 314 Programming Languages Functional Parsers Dr. Hyunyoung Lee 1 What is a Parser? A parser is a program that takes a text (set of tokens) and determines its syntactic structure. String or [Token]

More information

Chapter 15. Functional Programming Languages

Chapter 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 information

An introduction to functional programming. July 23, 2010

An 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 information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End

More information

JVM ByteCode Interpreter

JVM ByteCode Interpreter JVM ByteCode Interpreter written in Haskell (In under 1000 Lines of Code) By Louis Jenkins Presentation Schedule ( 15 Minutes) Discuss and Run the Virtual Machine first

More information

Types and Static Type Checking (Introducing Micro-Haskell)

Types and Static Type Checking (Introducing Micro-Haskell) Types and Static (Introducing Micro-Haskell) Informatics 2A: Lecture 14 John Longley School of Informatics University of Edinburgh jrl@inf.ed.ac.uk 17 October 2017 1 / 21 1 Types 2 3 4 2 / 21 So far in

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2018 Lecture 7b Andrew Tolmach Portland State University 1994-2018 Dynamic Type Checking Static type checking offers the great advantage of catching errors early And

More information

Practical Haskell. An introduction to functional programming. July 21, Practical Haskell. Juan Pedro Villa-Isaza. Introduction.

Practical 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 information

Typed Racket: Racket with Static Types

Typed Racket: Racket with Static Types Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type

More information

7. Introduction to Denotational Semantics. Oscar Nierstrasz

7. 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 information

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad-00 014 Subject: PPL Class : CSE III 1 P a g e DEPARTMENT COMPUTER SCIENCE AND ENGINEERING S No QUESTION Blooms Course taxonomy level Outcomes UNIT-I

More information

1. 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. 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 information

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Haskell 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 information

CPS 506 Comparative Programming Languages. Programming Language Paradigm

CPS 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 information

CIS 194: Homework 6. Due Wednesday, 4 March. Fibonacci numbers. It s all about being lazy.

CIS 194: Homework 6. Due Wednesday, 4 March. Fibonacci numbers. It s all about being lazy. CIS 194: Homework 6 Due Wednesday, 4 March It s all about being lazy. Fibonacci numbers The Fibonacci numbers F n are defined as the sequence of integers, beginning with 1 and 1, where every integer in

More information

Streams and Evalutation Strategies

Streams and Evalutation Strategies Data and Program Structure Streams and Evalutation Strategies Lecture V Ahmed Rezine Linköpings Universitet TDDA69, VT 2014 Lecture 2: Class descriptions - message passing ( define ( make-account balance

More information

Option Values, Arrays, Sequences, and Lazy Evaluation

Option Values, Arrays, Sequences, and Lazy Evaluation Option Values, Arrays, Sequences, and Lazy Evaluation Björn Lisper School of Innovation, Design, and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ Option Values, Arrays,

More information

Introduction to Haskell

Introduction to Haskell Introduction to Haskell Matt Mullins Texas A&M Computing Society October 6, 2009 Matt Mullins (TACS) Introduction to Haskell October 6, 2009 1 / 39 Outline Introduction to Haskell Functional Programming

More information

6.001 Notes: Section 15.1

6.001 Notes: Section 15.1 6.001 Notes: Section 15.1 Slide 15.1.1 Our goal over the next few lectures is to build an interpreter, which in a very basic sense is the ultimate in programming, since doing so will allow us to define

More information

Programming Languages Third Edition

Programming 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 information

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Module # 02 Lecture - 03 Characters and Strings So, let us turn our attention to a data type we have

More information

Macros & Streams Spring 2018 Discussion 9: April 11, Macros

Macros & Streams Spring 2018 Discussion 9: April 11, Macros CS 61A Macros & Streams Spring 2018 Discussion 9: April 11, 2018 1 Macros So far, we ve mostly explored similarities between the Python and Scheme languages. For example, the Scheme list data structure

More information

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Functional Parsers

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Functional Parsers 1 CSCE 314: Programming Languages Dr. Flemming Andersen Functional Parsers What is a Parser? A parser is a program that takes a text (set of tokens) and determines its syntactic structure. String or [Token]

More information

LECTURE 16. Functional Programming

LECTURE 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 information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques () Lecture 20 February 28, 2018 Transition to Java Announcements HW05: GUI programming Due: THURSDAY!! at 11:59:59pm Lots of TA office hours today Thursday See Piazza

More information

CS 457/557: Functional Languages

CS 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

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

CSCE 314 Programming Languages. Monadic Parsing

CSCE 314 Programming Languages. Monadic Parsing CSCE 314 Programming Languages Monadic Parsing Dr. Hyunyoung Lee 1 What is a Parser? A parser is a program that takes a string of characters (or a set of tokens) as input and determines its syntactic structure.

More information

YOLOP Language Reference Manual

YOLOP Language Reference Manual YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language

More information

Informatics 1 Functional Programming Lectures 13 and 14 Monday 11 and Tuesday 12 November Type Classes. Don Sannella University of Edinburgh

Informatics 1 Functional Programming Lectures 13 and 14 Monday 11 and Tuesday 12 November Type Classes. Don Sannella University of Edinburgh Informatics 1 Functional Programming Lectures 13 and 14 Monday 11 and Tuesday 12 November 2013 Type Classes Don Sannella University of Edinburgh Mock exam Slots and rooms have now been assigned Mon 18

More information

Programming with Math and Logic

Programming 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 information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

Background Operators (1E) Young Won Lim 7/7/18

Background Operators (1E) Young Won Lim 7/7/18 Background Operators (1E) Copyright (c) 2016-2018 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

More information

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) CSE 413 Languages & Implementation Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1 Goals Representing programs as data Racket structs as a better way to represent

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

More information

Imperative languages

Imperative 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 information

Processadors de Llenguatge II. Functional Paradigm. Pratt A.7 Robert Harper s SML tutorial (Sec II)

Processadors de Llenguatge II. Functional Paradigm. Pratt A.7 Robert Harper s SML tutorial (Sec II) Processadors de Llenguatge II Functional Paradigm Pratt A.7 Robert Harper s SML tutorial (Sec II) Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra Paradigm Shift Imperative Paradigm State Machine

More information

To figure this out we need a more precise understanding of how ML works

To figure this out we need a more precise understanding of how ML works Announcements: What are the following numbers: 74/2/70/17 (2:30,2:30,3:35,7:30) PS2 due Thursday 9/20 11:59PM Guest lecture on Tuesday 9/25 o No RDZ office hours next Friday, I am on travel A brief comment

More information

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017 Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

More information

To figure this out we need a more precise understanding of how ML works

To figure this out we need a more precise understanding of how ML works Announcements: What are the following numbers: 52/37/19/6 (2:30,3:35,11:15,7:30) PS2 due Thursday 9/22 11:59PM Quiz #1 back in section Monday Quiz #2 at start of class on Thursday 9/22 o HOP s, and lots

More information