CSE 341 -- Programming Languages

Autumn 2001

Department of Computer Science and Engineering, University of Washington

Steve Tanimoto (instructor)

Assignment 4

Version 1.0 of November 2 (Subject to Change)

A Taste of ML 

Due date and time: Thursday, November 8, 2001 (at the beginning of section).

Turn in this assignment as a hardcopy printout. However, electronic copies of the ML files will also be required; additional turn-in instructions will be announced later.


 

Title: A Taste of ML

Purposes: 1. Get an exposure to ML. 2. Get insight into ML's type facilities.

Instructions: Display the online document "A Gentle Introduction to ML" by Andrew Cumming. Read Lesson 1 and Lesson 2.
Part A: Simple Exercises Make up an expression that will evaluate to...

  • A real number expressing the volume of a sphere in terms of PI and the radius of the sphere.
  • A tuple representing today's date with a numeric day of the month, string month, and numberic year.
  • A list representing the days of the week as strings.
  • A function that returns the principal fourth root of its argument.
  • A function that accepts a tuple of three numbers representing a quadratic equation and that returns a list of the real roots of the equation.
  • A function genprefixer that accepts a string argument S1 and that returns a new function that also takes a string argument S2 and that returns S1 concatenated with S2.

  • Part B: Larger Chunks
  • Design and implement two versions of a function that will take an int list and return a new int list in which each is repeated as in the following example:
    - repeatElts [3, 1, 4, 1, 5, 9];
    val it = [3, 3, 1, 1, 4, 4, 1, 1, 5, 5, 9, 9] : int list
    
    Do this in two ways. The first should be called repeatElts1 and should use an if expression and should not use patterns. The second should be called repeatElts2, should use patterns, and should not use an if expression.
  • Declare a datatype tnode that is either a leaf node containing a string or is an internal node containing a string and two tnodes (one for the left subtree and one for the right subtree).
    Write a function inorderConcat that takes a tnode and returns a string that consists of all the strings from the nodes concatenated together and separated by blanks. Use "inorder" traversal, meaning that all left subtree strings come before the root's string, and all right subtree strings come after the root's string. Demonstrate your implementation of inorderConcat on a tree that represents an English sentence of at least 8 words in length.
  • Group Work:  This assignment should be performed individually (not in groups).