Write an SR program that implements the merge sort using only the `send' and `receive' of message passing. An array to be sorted is split in half and given to two processes. Each process sorts its half of the array and then sends, one at a time and in sorted order, its part of the array to a merge process. The merge process takes the smaller of the two numbers (or the next number available if one of the two sorts has had all its numbers read) and places it into the next available slot of the final sorted array.

Create three processes: two sorts and a merge. To one sort, pass the first half of the unsorted array; to the other sort, pass the other half. As the sorts progress in parallel, they will send to the merge process the sorted elements of their half of the array one-by-one as they are determined. In parallel with the sorts, the merge will receive the next element from the appropriate sort and place it into the final sorted array.

Make sure you test your program on a set of numbers that is already sorted and on another that is in reverse sorted order. You should also make sure your program handles requests to sort arrays of length two, length one, length zero, and illegal negative length.

The following array of channel construction technique may be useful.

resource sort
   import merge
body sort(id : int; merge_cap : cap merge)
   var item : int := id
      #...
   send merge_cap.channel[id](item)
      #...
end sort

resource merge
   import sort
   op channel[1:2](item : int)
body merge()
   var value : int
      #...
   fa i := 1 to 2 -> create sort(i, myresource()) af
      #...
   fa i := 1 to 2 ->
      receive channel[i](value)
      write("merge received value", value, "on channel", i)
   af
      #...
end merge


Animate the merge sort program you wrote.