NEED THR FOLLOWING DONE IN MIRANDA PROGRAMMING
SECTION A (Currying & Higher Order Functions (HOFs)
1. This question repeats Q1-4 from coursework 1, however you are required to
write curried, HOF answers.
a) Write the function <squareInc>, which given a list of numbers returns a
list of those numbers incremented and then squared. Eg: squareInc[1,2,3]
evaluates to the list [4,9,16] {4 marks}

Write the function <avgEven>, which given a list of numbers returns the sum
of all the even numbers in the list divided by the number of even numbers in
the list. Eg: avgEven [4,21,8] evaluates to 6 (ie (4+8)/2) {4 marks}
c) Write the function <partition> which given a list of numbers will return
a pair of lists, where the first list contains the positive numbers and the
second list contains the negative numbers. Discard all fractional numbers.
Eg: partition [1,-20.1,-4.0,3,3.1,-2] evaluates to ([1,3],[-2]) {4 marks}
d) Write <unMatched> which given two lists of any type will return the number
of items with a different value in any given position. For example:
unMatched ([1,2,3,4,6],[3,2,4,4,6]) => 2 (not matched in 1st & 3rd position)
{4 marks}
e) Compare your answers for the above with those for Coursework 1. {8 marks}
2. Write <sublist> which gives the mth to the nth element in a list (counting
from position 1). For example: sublist 3 5 "abcdef" ==> "cde" {6 marks}
3. Write <replace> which replaces the first instance of an item in a list.
For example: replace 6 888 [4,2,6,7,9] ==> [4,2,888,7,9].
You are not required to validate this function. {6 marks}
4. Use <foldl> or <foldr> to write <revAll> which given a list of lists returns
a single reversed list. For example: revAll ["abc", "de", "fgh"] gives the
list "hgfedcba". {6 marks}
5. Use functions from the Miranda Standard Environment to write <zipTwo> which
combines two lists. For example: zipTwo "ab" [1,2] gives [('a',1), ('b',2)].
{4 marks}
6. Explain (by rewriting, hand-evaluation, examples or otherwise) which,
if any of the pair of definitions (f1 & f2), (f3 & f4) or (f5 & f6)
are equivalent: {9 marks}
a) f1 = foldr ((+) . (*2)) 1
f2 = foldl ((+) . (*2)) 1

f3 f g = filter f . map g
f4 f g = map g . filter f
c) f5 = map
f6 f = foldr ((

. f) []
SECTION B (Algebraic types)
6. Clock algebraic type {10 marks}
a) Create an algebraic type <clock> to represent a 24 hour clock.

Write <makeClock> which takes a triple (representing hours, minutes and
seconds and creates an instance of the <clock> type.
c) Write <isMorning> to check if a <clock> value is in the morning
d) Write <addHour> which adds an hour to a given <clock> value.
7. Digraph algebraic type {25 marks}
A directed graph (digraph) consists of a set of nodes and a set of edges;
where a node represents a value, an edge is a connection between two nodes,
and all edges have directions (ie from a source to a target node). Each edge
is unique. Thus (1,2) represents the edge from node 1 to node 2.
a) Represent a digraph as an algebraic type; each edge should be represented
as a pair of numbers, and the graph itself as a list of pairs.

Write <makeGraph> to convert a list of pairs of numbers to a digraph.
c) Write <hasEdge> to check if an edge is a member of a digraph.
d) Write <swapDirections> to change the direction of all edges in a digraph.
Nb: swapping the direction of the edge (1,2) will give the edge (2,1).
e) Write <isAdjacent> to check if any two edges are directly connected.
Eg: (1,2) is adjacent to (3,1) and (2,4) but not (1,3).
f) Write <allAdjacent> to list all edges that are adjacent to a given edge.
g) Write <hasPath> to check if a digraph contains a given path, ie if a given
sequence of adjacent edges appear in the graph. Eg: [(1,2), (2,4), (4,6)]
appears as a path in the digraph [(1,2), (2,4), (6,3), (3,5), (4,6)].
(Bonus marks if you check that the path is actually connected.)
DOCUMENTATION REQUIREMENTS (FOR BOTH SECTIONS): {10 marks}
You are expected to produce a literate script with sensible documentation
(layout, comments and names). All functions should be preceded by type
declarations. sensible use should be made of higher order functions, currying,
where clauses, type synonyms and a functional style. Do not include test runs
or test data.