Homework 14: Building ML Programs
Create an sml file named hw14.sml and, in it, define each of the following functions.
- 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.
- 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.- Write a function that takes a list such as ["up","down","up","up] and "flips" each element, returning ["down","up","down","down"].
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- Write a function, merge, which takes two sorted lists and yields a sorted list consisting the elements from the two original lists.
- Write a function, mergesort, which uses the above three function definitions to perform a mergesort on a list of integers.
- Others: For extra credit consideration, implement some other sorting algorithm in ML.