Back
ExamFull examExam paper only

24 09 12 1

Full exam for Principles of Programming Languages in the Computer Engineering degree programme at Politecnico di Milano. The document covers: Principles of Programming Languages 2012.09.24 Notes • Total available time: 2h 30’. • You may use any written material you need. • You cannot use computers, phones or laptops during the exam 1 Haskell (10 points) 1. Please define a procedure getCSV that is used, in the Monad IO,

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 2012.09.24 Notes • Total available time: 2h 30’. • You may use any written material you need. • You cannot use computers, phones or laptops during the exam 1 Haskell (10 points) 1. Please define a procedure getCSV that is used, in the Monad IO,

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 2012.09.24 Notes • Total available time: 2h 30’. • You may use any written material you need. • You cannot use computers, phones or laptops during the exam 1 Haskell (10 points) 1. Please define a procedure getCSV that is used, in the Monad IO, to get a field in a Comma Separated Values textfile (assume as separators both the , and ; characters). 2. Define the unless procedure in the IO Monad. It takes two arguments, a condition c and a body b, and repeats b unless c becomes true (in a sense, it is a “dual” of while). 3. Alfio is experimenting with Haskell, and wants to define a very simple object-oriented-like system, where an object is just a container of a datum, and a list of “methods”, i.e. functions having signature a→ a→ a, where a is the type of the datum. This is an example object defined by Alfio: myob = Obj (5, [("add", \self -> \x -> self+x), ("sqr", \self -> \x -> self*self)]) -- x is ignored Please, help Alfio to define both the needed datatype, and the call function for invoking methods. E.g. call myob "add" -2 should return 3. 2 Prolog (8 points) 1. Please, define a Prolog procedure to obtain from a list the last but one element. If the number of elements in the list is less than 2, it should fail. 2. Define a nested version of the previous procedure: when the last but one element of the list is another list, this new procedure should look to the last but one element, until it finds an atomic value. E.g. ?- nestedlastb1([1,2,[3,3,[5,2,2],6],4],X). X = 2. 1 3 Scheme (7 points) Scheme does not natively support matrices: there are just vectors. Of course, we can define a matrix as a vector of vectors, each having the same size. 1. Please define make-matrix, with three parameters: r, c, and f ill. This procedure returns a matrix having…

Preview

First page of the document.

First page: 24 09 12 1