Computer Science 173
Intermediate Computer Programming

Denison
CS173 Homework 14

Homework 14: Building ML Programs

Create an sml file named hw14.sml and, in it, define each of the following functions.

  1. Write a function named add1 that adds one to its input. Then write a function addlist that applies the function to each element in a list.
  2. Let the symbol dailyplanet be bound to the following list of tuples:
    val dailyplanet = [("olsen","jimmy",123764535),
    ("kent","clark",089526787),
    ("lane","lois",951261438),
    ("white","perry",355167439)];
    Each tuple consists of a last name, first name, and a social security number. Write a function to extract a list of social security numbers.
  3. Write a function that takes a list such as ["up","down","up","up] and "flips" each element, returning ["down","up","down","down"].
  4. Write a function, onetofive, to construct a list whose elements are those from an input list with values greater than one and less than five.
  5. Write a function, filterless, that takes an integer and a list as input and yields the sublist whose values are less than or equal to the given integer.
  6. Write a function, filtergreater, that takes an integer and a list as input and yields the sublist whose values are greater than the given integer.
  7. Using the two previously defined functions, define a function, quicksort, to perform a quicksort where the pivot value is the first element of a given list.
  8. Write a function, front, that takes an integer, n, and a list and returns the sublist whose elements are the front n elements of the original list.
  9. Write a function, remain, that takes an integer, n, and a list and returns the sublist whose elements are the remainder of the original list after the first n elements have been removed from the list.
  10. Write a function, merge, which takes two sorted lists and yields a sorted list consisting the elements from the two original lists.
  11. Write a function, mergesort, which uses the above three function definitions to perform a mergesort on a list of integers.
  12. Others: For extra credit consideration, implement some other sorting algorithm in ML.