Functions and Data.
a priority queue type to keep track of monster attacks. I
encourage you to write the functions in the order I have listed them
here, and stop to test your code at every opportunity along the way.
Text.Show.Functions and Data.List
a MonsterAttack type with a monster name and a float distance that
represents the distance from Tokyo of the attack.
a function that compares two MonsterAttacks and returns the one for
which the monster name is later in lexicographic order (you can use
the > operator for this)
another function that compares two MonsterAttacks and returns the one
with the smaller distance
a priority queue type with a list of monster attacks and a sorting
function (which will be taken as a parameter when you construct an
instance). This type should derive Show. The sorting
function should have the same signature as the two comparison
functions you have just written.
an offer method that adds a MonsterAttack to the list in a priority
queue and returns a new priority queue. My priority queue class
was called MPQ. The signature for this function was as follows:
:: MPQ -> MonsterAttack -> MPQ
a size function that takes a priority queue and returns the
length of the list of monster attacks that is part of that queue.
a function that takes a priority queue and a MonsterAttack and
removes that attack from the queue if it is present.
a poll function that takes a priority queue and returns a tuple
(MonsterAttack, PriorityQueue) in which a) the Monster Attack is the
one that is the one with the minimum priority based on your
comparison function (ie, the one with the name that is *last* in lex
order or the one that is closes to Tokyo, depending on which
comparison function you used to crate the priority queue) and
b) the priority queue is identical to the one that came in a s a
parameter, but with the minimum MonsterAttack removed. Think
for a minute about why, with no side effects, you have to do it this
way. My poll function calls a separate recursive function in order to
find the minimum value in a way that is similar to the example in the
lecture, then creates the tuple using the return value form the
one or more functions to take a list of MonsterAttacks and a
comparison function and create a priority queue.
a function that takes a priority queue and returns a sorted list of
MonsterAttacks by polling and putting the results in a new list until
the queue is empty. the sort order should be the one defined by
the comparison function you used to create the queue (ie, descending
lex order or ascending distance from Tokyo).
in your code and screen shots showing the results of the sort
function for a) a priority queue that uses the reverse lex order
comparison and b) one that uses the distance from Tokyo comparison
The post Functions and Data appeared first on My Assignment Online.