1. (a) There are now a number of programming paradigms available to us,
such as procedural, declarative, object-oriented, and functional
(sometimes referred to as "applicative") programming.
Suggest a number of reasons why functional programming
languages are worthy of study. You should address this question
from both a theoretical and a practical perspective.
(5 marks)
(b) It might be said that "All functions in ML take a single argument".
This statement appears to be incorrect when we look at the
definitions of the two functions below, mult and prod, both of
which deliver as a result x times y.
fun mult (x,y) = x*y:int;
fun prod x y = x*y:int;
Explain why the above statement is true, namely that all functions
in ML do indeed have a single argument. You should use the functions
mult and prod to clarify your answer.
(4 marks)
(c) We can represent a binary number as a list of zeros and ones, with
the least significant bit as the head of the list. For example the
binary representation of 8 would be the list [0,0,0,1]. Write a
function in ML, called convert, that takes an integer and delivers
its binary equivalent as a list of zeros and ones.
(4 marks)
(d) Write a function in ML, called add_bin, that adds together two
numbers, where those numbers are binary numbers represented as
lists of zero's and one's (ie. numbers that might have been produced
by the function convert above, such that the least significant digit
is the head of the list). HINT: you might find it is helpful
to define a function called add_digits (c,x,y), where add_digits
adds the carry c, the x, and y, and delivers as a result
the pair (result,new_carry). This may then be used to construct
the function add_bin.
(12 marks)