REVISED 11/25/2015
Prepare a Haskell program that includes the following function
definitions and PutStrLn calls to show that they work as
intended. The program needs to run on the GL platforms. As before,
use the UNIX script command to list the program and the
results. Email the file to me and the TA
Rujuta Palande no later than
midnight Tuesday/Wednesday December 8, 2015. Work submitted
before Thursday December 3 may be eligible for extra credit.
You are free to install Haskell on your own PC, if you wish. Just be able to prove that your program ran as required.
Choose any six of these seven exercises. If you do all seven, that too may be eligible for extra credit.
replicate :: Int -> a -> [a]
that
produces a list of identical elements. For example,> replicate 3 "tsk"
["tsk","tsk","tsk"]
median :: [Int] → Int
that
finds the median of a list of integers. The median is the element that is in the middle when the list is sorted. If the list is of even length, the median is the arithmetic mean of the two middle elements. The median of the empty list is for you to decide, but zero or the empty list itself are reasonable choices. Your function may use a built-in sort function if you wish, although this isn't necessary. The cheat sheet file haskellCS2.hs has an example of how the built-in sort function is used. The median function would work as shown here: > median [1,2,3,4,5,6]
3.5
> median [11, 2, 13]
11
merge :: Ord a ⇒ [a] → [a]
→ [a]
that merges two sorted lists to give a single sorted
list. The two input lists need not be the same length. One or both may be empty. Your definition should be defined using explicit
recursion. For example> merge [2,5,6] [1,3,4]
[1,2,3,4,5,6]