Docsity

Homework 10 Solution Manual - Computer Science | CIS 252, Assignments of Computer Science

Toggle sidebar
bg1
Homework 10 CIS 252 (Spring 2009) — Introduction to Computer Science
Coverage
This assignment focuses on material in Chapter 18 of Haskell: The Craft of
Functional Programming (HCFP).
Logistics
This homework is officially due in the bin in CST 3-212 by noon on Thurs-
day, April 23. However, it comes with an automatic extension: anything
submitted by noon on Friday, April 24 will be accepted as being on time.
You may work singly or in pairs on this assignment.
As always, you’re expected to follow the design recipe discussed in lec-
ture.
Turn in a hard copy of your source code and a transcript demonstrating
convincingly that your code is correct. Also, submit your code (but not
transcript) electronically.
Exercises
1. HCFP, Exercise 18.3
2. HCFP, Exercise 18.4
Hint: We covered checking for palindromes in lecture just before
Spring Break.
3. HCFP, Exercise 18.5
Hint: Insertion sort (described in the text) is a useful sort for this
situation.
4. Write a Haskell function
printBack :: Int -> IO ()
such that (printBack n) reads nlines of text and then displays
them, one per line, in reverse order. For example, your function
should have the following behavior:
Main> printBack 4
here’s one line
here’s a second
and the third
fourth (and last)
fourth (and last)
and the third
here’s a second
here’s one line
Page 1

Partial preview of the text

Download Homework 10 Solution Manual - Computer Science | CIS 252 and more Assignments Computer Science in PDF only on Docsity!

Homework 10 CIS 252 (Spring 2009) — Introduction to Computer Science

Coverage

This assignment focuses on material in Chapter 18 of Haskell: The Craft of Functional Programming (HCFP).

Logistics

This homework is officially due in the bin in CST 3-212 by noon on Thurs- day, April 23. However, it comes with an automatic extension: anything submitted by noon on Friday, April 24 will be accepted as being on time.

You may work singly or in pairs on this assignment.

As always, you’re expected to follow the design recipe discussed in lec- ture.

Turn in a hard copy of your source code and a transcript demonstrating convincingly that your code is correct. Also, submit your code (but not transcript) electronically.

Exercises

  1. HCFP, Exercise 18.
  2. HCFP, Exercise 18. Hint: We covered checking for palindromes in lecture just before Spring Break. 3. HCFP, Exercise 18. Hint: Insertion sort (described in the text) is a useful sort for this situation. 4. Write a Haskell function

printBack :: Int -> IO ()

such that (printBack n) reads n lines of text and then displays them, one per line, in reverse order. For example, your function should have the following behavior:

Main> printBack 4 here’s one line here’s a second and the third fourth (and last) fourth (and last) and the third here’s a second here’s one line

Page 1