Back
ExamFull examExam paper only

10 09 15

Full exam for Principles of Programming Languages in the Computer Engineering degree programme at Politecnico di Milano. The document covers: Principles of Programming Languages 2015.09.10 Notes • NAME: __________________________________ • Did you present a small project? YES / NO • Total available time: 1h 30’. • Y ou may use any written material you need. • Y ou cannot use computers or phones during the exam. 1

Principles of Programming LanguagesFull exam

Document information

What's included in this study material

Full exam for Principles of Programming Languages in the Computer Engineering degree programme at Politecnico di Milano. The document covers: Principles of Programming Languages 2015.09.10 Notes • NAME: __________________________________ • Did you present a small project? YES / NO • Total available time: 1h 30’. • Y ou may use any written material you need. • Y ou cannot use computers or phones during the exam. 1

Import quality: text was extracted directly from the original document.

Extracted content from the document

Representative passages recognised in different parts of the material. The full extracted text remains available to search, while this compact preview makes the page easier to read.

Page 1

Principles of Programming Languages 2015.09.10 Notes • NAME: __________________________________ • Did you present a small project? YES / NO • Total available time: 1h 30’. • Y ou may use any written material you need. • Y ou cannot use computers or phones during the exam. 1 Scheme Consider the following procedure: (define (re-map f L cond?) (let loop ((res ’()) (cur L)) (if (null? cur) res (let* ((k #f) (v (call/cc (lambda (cont) (set! k cont) (f (car cur)))))) (if (cond? v) (cons k v) (loop (append res (list v)) (cdr cur))))))) 1.1 Description (5 points) Give a brief explanation of what re-map does, providing also a simple but meaningful example of its use and return value, different from the one of the next question. 1.2 Example usage (5 points) Let us consider to use re-map at the REPL with the following command: > (define V (re-map (lambda (x) (+ x 1)) ’(0 1 -4 3 -6 5) negative?)) Give a sequence of related commands such that the result of the last command is the list (1 2 3 4 5 6) . 1 2 Haskell 2.1 Class definition (3 points) Define a class called Blup, for a generic type T having two parameters x and y, providing two operations called f isto and f osto. f isto takes a value belonging to T and returns a value of type M aybe x, while f osto takes a value belonging to T and returns a value of type M aybe y. 2.2 Instance I (4 points) Define the sum type Blargh with two parameters of types a and b. It has three data constructor: either Bip with two parameters of types respectively a and b, or Bop with only one parameter of type a, or Bup with no parameters. Make Blargh an instance of class Blup, where f isto is used to access to data of type a, and f osto to data of type b. 2.3 Instance II (4 points) Define the sum type Blarf with two parameters of types a and b. It has…

Preview

First page of the document.

First page: 10 09 15