CPSC 425 Spring 2008
HW 4: Patterns and Local Variables in ML
- Look back at the Chapter 5 ML exercises you did for HW 2 and HW 3.
Choose an exercise that you really struggled with but did finally get
a solution for. Now use this exercise to answer the following questions:
- Write a solution for the same exercise in the language
you are most comfortable with -- probably Java or C++ -- the way you think
you would have gone about it before working with ML.
- Compare your ML
solution to your "comfortable" (Java/C++) solution. Beyond syntax, how
are they different? How are they similar? Why did you have so much more
trouble with the ML solution than with the comfortable solution? If the
answer is just syntax -- for example, you kept forgetting to use "andalso"
instead of "and" -- choose another exercise and see if you find more
interesting differences.
- Would you argue that your ML solution is somehow better than your Java/C++
solution, or vice-versa? Why or why not?
- Read sections 7.1-7.7 about pattern matching in ML. Then rewrite
your solutions to exercises 3, 5, 7, 9, and 10 in Chapter 5 using
pattern-matching style.
- Read section 7.8 about local variable definitions in ML. Study the
definition of function halve; trace
the call halve [1,2,3,4,5,6] by showing the parameter and return
value for each recursive call.
All of your answers should be typed, not hand-written.
You do not need to e-mail them to me; just bring hardcopy to class on Tuesday.