← Indietro
EsameEsame completoTesto d’esame

10 09 15

Esame completo di Principles of Programming Languages per il corso di Computer Engineering presso Politecnico di Milano. Materiale proveniente dall’archivio storico Studwiz e classificato per la consultazione online.

Principles of Programming LanguagesEsame completo

Informazioni sul documento

Cosa trovi in questo materiale

Esame completo di Principles of Programming Languages per il corso di Computer Engineering presso Politecnico di Milano. Materiale proveniente dall’archivio storico Studwiz e classificato per la consultazione online.

Qualità dell’importazione: il testo è stato estratto direttamente dal documento originale.

Contenuti estratti dal documento

Passaggi rappresentativi riconosciuti nelle diverse parti del materiale. Il testo completo resta presente nella pagina per la ricerca, mentre l’anteprima compatta rende più semplice la lettura.

Pagina 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…

Anteprima

Prima pagina del documento.

Prima pagina: 10 09 15