whm's CSC 372 Exam (and Quiz) Archive

The 372 landscape keeps changing

The set of languages covered in 372 has changed over time. When I first taught it in 1996 the line-up was ML, Icon, C++, and Prolog. The department went from teaching OOP with C++ as a forward-looking paradigm in 372 in Spring 1997 to teaching OOP with Java in the introductory courses in Fall 1998. In 2001 my 372 line-up was ML, Icon, Prolog, and a little bit of Emacs Lisp. In 2006 I replaced Icon with Ruby. Haskell had been taught in 372 by Dr. Collberg in recent years but Spring 2014 was my first time to teach Haskell in 372.

The ML problems are essentially good practice for Haskell, but some translation is necessary. Here's a quick guide:

Haskell Standard ML Notes
> add x y = x + y > :t add add :: Num a => a -> a -> a - fun add x y = x + y; val add = fn : int -> int -> int ML doesn't have the notion of type classes like Num.
> :t ('x', False) ('x', False) :: (Char, Bool) - (#"x", false); val it = (#"x",false) : char * bool ML represents tuple types with type * type.

#"x" is a character literal in ML.

Rather than representing strings as lists of characters, ML has a string type. The explode and implode functions are used to convert back and forth:

- explode;
val it = fn : string -> char list

- explode "abc";
val it = [#"a",#"b",#"c"] : char list

- implode (rev it);
val it = "cba" : string
> swap (x,y) = (y,x) > :t swap swap :: (t1, t) -> (t, t1) - fun swap (x,y) = (y,x); val swap = fn : 'a * 'b -> 'b * 'a ML type variables are a, b, ... preceded by an apostrophe. 'a is read as "alpha", 'b as "beta", etc.
> headEquals (h:_) value = h == value > :t headEquals headEquals :: Eq a => [a] -> a -> Bool - fun headEquals (h::_) value = h = value; val headEquals = fn : ''a list -> ''a -> bool cons in ML is two colons, not one.

''a requires the type to be one whose values can be compared for equality—a rough analog for Haskell's Eq type class.

You'll find Ruby problems in my Fall 2006, Spring 2014, and Spring 2015 exams but a number of the Icon problems on the older exams are the sort of problems I'd ask you to do in Ruby. However, students were limited to Icon's built-in functions so there may be some problems that would be trivialized with Ruby's big library. Icon problems involving "string scanning" can typically be handled with regular expressions but it's not 100%. Icon questions about generators and result sequences don't have a good analog in Ruby.

Examinations and Solutions

Quizzes and Answers, in a single PDF

Errata

Spring 2015 midterm solutions

Spring 2016 midterm solutions