CSE 341 - Spring 2002 - Assignment 1 - Miranda Warmup

Due April 8, at the beginning of class. Please submit all of your function definitions in one code file and your testing output in a separate file. Use comments to clearly indicate which problem number each section of code/output matches.

  1. You don't need to hand in anything for this first question. Experiment a bit with Miranda. Try testing some of the built-in functions. Experiment with Miranda's type system: find the type of some constants, of some built-in functions such as member and map, and of some partially applied functions, e.g.
    (const 1)
    
    Try to enter some ill-typed expressions, such as
    [1,2,[3],4]
    or
    member [1] "fred"
    .
  2. Write and test a Miranda function mean that finds the mean (average) of a list of numbers. Do something sensible if you get an empty list as an argument.
  3. Write and test a Miranda function sdev that finds the standard deviation of a list of numbers. (Similarly, do something sensible about empty lists.) The standard deviation is a measure of dispersion -- if all the numbers are the same, the standard deviation is 0. It is defined as the square root of the mean of the squares of the differences of each number from the mean of the list. For example, the mean of [1,2,6] is 3. So the standard deviation is
    sqrt (( (1-3)^2 + (2-3)^2 + (6-3)^2 ) / 3)
    
    which is 2.160246899469
  4. Write and test a Miranda function duplicate that takes a number n and some other value x, and returns a list of n x's. For example:
    duplicate 3 "squid"  =>  ["squid","squid","squid"]
    duplicate 0 True     => []
    
    Also, what is the type of duplicate? (You may answer this in a comment with your function definition.)