Question 1

Estimated completion time: 10 minutes

Write a procedure and a call to it in block-structured pseudocode such that the execution of the procedure under pass-by-reference, pass-by-value and pass-by-value/result yields different outcomes. Justify your answer.


Question 2

Estimated completion time: 30 minutes

a) For three different languages of your choice, give an example of a weakness in the type system, explaining how it leads to a run-time error.

b) What is the type of the expression

  fn f => fn g => fn x => f( g( f x ) )

given by the SML interpreter? Explain how this is inferred.

c) For each of the following ML declarations, either justify their ability to be soundly used or give a program using them which would violate type safety:

d) Give an example of the following constructs

in the SML Modules language.


Question 3

Estimated completion time: 40 minutes

a) List two language innovations of the programming language Scala. Justify your answer.

b) Comment on the mechanism for parameter-passing in the programming language Scala. You may wish to consider the following two code samples.

def whileLoop( cond: => Boolean )( comm: => Unit )
  { if( cond ) comm; whileLoop( cond )( comm ) }

def qsort[T]( xs: Array[T] )( implicit o: Ord[T] ): Array[T]
  = if( xs.length <= 1 ) xs else
    { val pivot = xs( xs.length/2 )
      Array.concat
        ( qsort( xs filter (x => x.lt(x,pivot)) ) ,
          xs filter (x => x == pivot ) ,
          qsort( xs filter (x => x.lt(pivot,x)) ) ) }

c) The programming language Scala introduced case classes. Explain why they are useful in programming, giving code samples

d) Explain how function types are encoded in the programming language Scala, exemplifying your answer


Question 4

Estimated completion time: 30 minutes

Explain the meaning of static (i.e. compile-time) and dynamic (i.e. run-time) type checking.

Compare the advantages and disadvantages of these two approaches to type checking from the point of view of the language designer, the language implementer, and the programmer.

Give an example of a program which is safe at run-time but will not statically type-check.


Question 5

Estimated completion time: 60 minutes

Read Chapter 10 (Concepts in OO) and Chapter 11 (Simula/Small talk) from Concepts in Programming Languages, Mitchell. Write brief notes on what you read.