CS330 Spring 2004 Lecture 7

George Tzanetakis

Slides 

This lecture will not contain any slides as it consists mainly of
programming examples in sml.

SML code

Code in text format

Assignment 1 in SML 

Suggested exercises

7.1) Make a datatype declaration for a type solution to express the three
possibilities for roots in a quadratic equation: two roots, one root, no roots.
Declare a corresponding solve function for solving the equation.

7.2) Declare a function of type int list -> int option for finding the minimum
element in an integer list

7.3) Declare a function partition(x,xs) to split the list xs of integers into
three lists (xs1,xs2,xs3), where xs1,xs2,xs3 are the lists of elements of xs which are
smaller than, equal and greater than x.

7.4) In some university students can take a course either as Pass/Fail
or for credit on a 10-point scale (1,..,10 are valid grades). A course is passed
when the grade is either Pass or greater than 5 on the 10-point scale.

a) Model grades using the datatype concept of SML
b) Declare an invariant determining whether a given mark is legal
c) Declare a function giving the number of passed courses for a collection
of grades