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 |
> let 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 .
Rather than representing strings as lists of characters, ML has a - explode; val it = fn : string -> char list - explode "abc"; val it = [#"a",#"b",#"c"] : char list - implode (rev it); val it = "cba" : string |
> let 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.
|
> let 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.
|
You'll find Ruby problems only in my Fall 2006 and Spring 2014 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%.