Haskell代写: 插入排序与交换排序

用Haskell实现插入排序与交换排序(近似与冒泡排序)。

Homework #2 - Sorts over Arrays

Homework #1 - Sorts over Arrays

In this home work we will write two sorting algorithms over arrays. An insertion sort, and an exchange sort. You are required to follow the steps of the design recipes we have studied in class.

Recall that every step in a design recipe cooresponds to a product. It must be the case that every product appears in your solution. It could be a comment, or some actual program fragment. Study the design recipes

  1. Generic program design recipe.
  2. Recursive program design recipe.
  3. Array processing design recipes.

For this homework you will create one haskell program which defines two functions. Study the problem description below for each function. Note that you are required to write two functions. You may write additional helper functions if you desire. You must include tests, and you must include a “main” function that acts as a “harness” and demonstrates (in addition to your tests) that the two functions work.

  1. insertionSort
  2. exchangeSort

Getting Started.

You will need to download the library file ArrCommands and put a copy in the same directory as your solution.

Your program will probaby look something like


-- Author Tom Smith
module HW02 where

import ArrCommands

insertionSort:: Array a -> IO ()

exchangeSort:: Array a -> IO ()


main =
  do { ... }

tests = ...

What to turn in.

Create a Haskell source file. Upload the file to blackboard by class time October 20, 2009. The file must have:

  • Your name (as the author of the program) indicated in a comment in the very first line
  • At least 2 function definitions, one for each of the assigned functions. You may define additional functions to help, or to create tests.
  • Products for each of the concrete steps in the generic design recipe
    1. Understand the problem
    2. Write a contract (type) for each function
    3. Create a set of examples (HUnit assertions)
    4. Create a body for each function where the body is based upon one of the design recipes above.
    5. Tests for each your functions (HUnit tests) including a named value “tests” that runs all your tests.
    6. A “main” function that acts as a “harness” and demonstrates (in addition to your tests) that the two functions work.
  • Any products from the recursive design recipe you deem to be usefull to the reader of your program.

Upload this file using the blackboard assignment mechanism.

Back to the Daily Record.

Back to the class web-page.

kamisama wechat
KamiSama