Abstract: We introduce a compiler for the functional quantum programming .... qbits from anywhere in a circuit to the top, putting what was originally first after.
generic programming based on the notion of a functional strategy: a first-class ...... eral, you need a dedicated type constructor TypeArg, and you need an actual ...
Jan 27, 2012 - To test the hypothesis, a good definition of âsecurityâ which is not specific to ... Whereas Tevis has used the chapters of the âSecure Programming Cookbook in C ...... https://www.owasp.org/index.php/Secure Coding Principles,.
1.4 Where Can I Find Necessary Files for Creating a Compiler in C? . ..... Hence,
there is no need for additional materials covering C implementation for. Chapter ...
Jun 5, 2015 ... Static Single Assignment Book ..... 16.3 Sparse Constant Propagation of Array
Elements .... 25 Building SSA form in a compiler for PHP.
2 based on CSE 504, Stony Brook University. Winter 2010. Static Checking. ▫
Static (Semantic) Checks. ▫. Type checks: operator applied to incompatible ...
Compiler Design 1. Introduction to Programming. Language Design and to
Compilation. Compiler Design 1 (2011). 2. Administrivia. • Lecturer: – Kostis
Sagonas ...
1. Introduction: Compiler Design. CSC532. Outline. • Course related info. • What
are compilers? • Why learning? • Introductory Anatomy of Compiler ...
1.6 To the lecturer. This book was written for use in the introductory compiler
course at DIKU, the .... separate lexical and syntactical elements of the languages
.
3.4.1 Rewriting ambiguous expression grammars . . . . . . . . 64 ... 3.13 Rewriting a
grammar for LL(1) parsing . ...... for presentation in this book. In such cases ...
Functional Programming in C++ using the FC++ Library. Brian McNamara and Yannis ... invite you to take a tour of FC++ and catch a glimpse of the possibilities.
Functional Programming in C++ using the FC++ Library. Brian McNamara and Yannis Smaragdakis. College of Computing. Georgia Institute of Technology.
Lawrence C. Paulson 1 and Andrew W. Smith 2. 1 Computer Laboratory .... guage, if pure logic programming is to become practical. So let us consider what.
loops with sub-optimal code (eg. badly vectorized, too big for the architecture ... data analysis use cases for guiding architecture parameters selection. Section V ...
Jul 30, 2004 ... Home Page. Title Page. ◁◁. ▷▷. ◁. ▷. Page 1 of 100. Go Back. Full Screen.
Close. Quit. •First •Prev •Next •Last •Go Back •Full Screen ...
To be efficient on a large set of applications, new architec- tures and compilers ... proposed approach for two compiler transformations: register allocation and ...
Dec 16, 2003 - In order to use a procedure, array or variable they must be declared first. ..... uIdentifier (ident-list), until the types of the parameters in ident-list have been determined ...... ident-item â int-ident | bool-ident | str-ident |
Languages and Compiler Design II. Parameter Passing. Material provided by
Prof. Jingke Li. Stolen with pride and modified by Herb Mayer. PSU Spring 2010.
To understand the theory and practice of compiler implementation. To learn finite
state machines and lexical scanning. To learn context free grammars, compiler
parsing techniques, construction of abstract syntax ... Code optimization: principle
so
âHelpâ in the subject line of your message, and mail it to: [email protected]. ..... type system of the Swift IR can represent all of the types present in a Java ...
1. Functional Programming and. Compiler Design. Praktikum WS 2001/2. Tobias
Nipkow & Norbert Schirmer. (Slides largely by Simon Thompson). 2.
The Web page
Functional Programming and Compiler Design
Backup materials: exercises, solutions, booklist, background etc. Hugs error messages
Praktikum WS 2001/2
The Hugs98 distribution and documentation.
Tobias Nipkow & Norbert Schirmer
...
(Slides largely by Simon Thompson)
4
Why functional programming?
Today:
Simple but powerful model of computing … … where you can understand the fundamentals of programming
Intro to functional programming in Haskell
Complements Java and OO programming … … helps you to understand them. New .... challenging ... fun
2
5
How is it taught?
What is a function?
Introduction to functional programming in Haskell
A function gives an output value which depends on some input values:
Weekly lectures in the first half of term Compiler Design 4 lectures + projects in the second half of term:
12
•Lexer and parser
34
•Static analysis
inputs
+
output
46
•Abstract machine •Code generation 3
6
1
Functions over pictures
Functions over pictures
A function to flip a picture in a vertical mirror:
A function to put one picture above another:
input
output
flipV
above
7
10
Functions over pictures
Functions over pictures
A function to invert the colours in a picture:
A function to put two pictures side by side:
invertColour
sideBySide
8
11
Functions over pictures
Types
A function to superimpose two pictures:
A type is a collection of values, like numbers or pictures. Grouped together because we can do the same things to them … … we can add two numbers, but we can't add a picture to a number, and indeed we can't add two pictures.
superimpose
9
12
2
Types and functions
Haskell and Hugs
Functions have types.
Haskell is a standard functional programming language, named after Haskell B. Curry.
Given inputs of particular types, they produce outputs of a certain type. Int Picture
+
Haskell98 is a recent `standard' version of the language. There are various implementations, including Hugs, which we use.
Picture Int
above Picture Int
Hugs works on Windows, Mac and Unix. Another standard functional language: ML 13
Expressions and evaluation
16
Expressions in functional programming
(7-3)+ 2
Applying a function …
An expression …
sideBySide horse (invertColour horse)
(7-3)+ 2 4+2 … yields a value (its result) …
… by evaluation
function
first argument
second argument
4+2 6
14
17
Expressions and evaluation sideBySide
(invertColour
)
(7-3)+ 2
An argument
sideBySide
operator
Evaluation in functional programming
An expression is made by applying a function or operator to arguments, which are also expressions. Can evaluate these expressions in a calculator. 15
(+) :: Int -> Int -> Int (+) :: Float -> Float -> Float
More on Haskell's type system later ... 43
~>
fac 2 * 3
~>
(fac 1 * 2) * 3
~>
((fac 0 * 1) * 2) * 3
~>
((1 * 1) * 2) * 3
~>
6
46
Pitfalls
Undefined or error values
Functions and other values begin with small letters … … types begin with capital letters.
The problem of fac (-2) … two solutions: fac n
Function min is already defined in the standard prelude of commonly used functions. If we want to redefine it we need to say:
| n==0
= 1
| n>0
= fac (n-1) * n
| otherwise
= 0
fac n
import Prelude hiding (min)
| n==0
= 1
| n>0
= fac (n-1) * n
| otherwise
= error "negative fac"
44
47
Recursion
Primitive recursion
Recursion means that a function is used in its own definition
What if I were given fun (n-1) ; how would I define fun n?
In Haskell all iterative computations are expressed by recursion - there is no need for loops (while or for)
A template or pattern: fun n | n==0
= ....
| n>0
= .... fun (n-1) ....
Example: powers of two. power2 :: Int -> Int 45
48
8
Powers and their sums
How many pieces with n cuts?
power2 :: Int -> Int
No cuts: 1 piece.
power2 n
With the nth cut, you get n more pieces:
| n==0
= 1
| n>0
= 2 * power2 (n-1)
cuts :: Int -> Int cuts n
How can you add the powers of two? sumPowers :: Int -> Int
| n==0
= 1
| n>0
= cuts (n-1) + n
| otherwise
= 0
sumPowers n = power2 0 + … + power2 n 49
Powers and their sums
52
Not everything is primitive recursive
How can you add the powers of two? gcd :: Int -> Int -> Int gcd m n
sumPowers :: Int -> Int
| n==0
= m
| otherwise
= gcd n (m `mod` n)
sumPowers n | n==0
= power2 0
| n>0
= sumPowers (n-1) + power2 n
| otherwise = 0
50
How many pieces with n cuts?
53
if then else If b::Bool and e1::T and e2::T then if b then e1 else e2 :: T Example: fac n = if n==0 then 1 else n*fac(n-1)
51
54
9
Local definitions: let and where
Layout
let x = 42 in x+x ~> 42+42 ~> 84
The way that a program is laid out in Haskell counts. Follow the style of the book …
Alternative: x+x where x=42 … otherwise can get bizarre error messages …
Works also for functions: f 42 where f 0 = 0 f n = f(n-1)
… which should lead you to the errors page.
55
58
What is a script? It defines a collection of fixed or constant things. size :: Int size = 12+13 flipRotate :: Picture -> Picture flipRotate pic = flipV (rotate90 pic)
flipRotate always has the same effect, and the value of size is always 25 … not like variables in Java. 56
Regular and literate scripts In a regular script there are definitions and comments:
In a literate script there are comments and definitions:
-- FirstScript.hs
FirstLit.lhs
-- 5 October 2000
5 October 2000
-- Double an integer.
Double an integer.
double :: Int -> Int
>
double :: Int -> Int
double n = 2*n
>
double n = 2*n
Everything is program, except comments beginning --.
Everything is comment, except program beginning > . 57