This preview shows pages 1–3. Sign up to view the full content.
CS 4536 - Haskell and Laziness AssignmentCS 4536 Homework 3: Haskell and LazinessDue: Thursday Jan 31, 11:59pm via turnin (assignment name hwk3) Collaboration Policy: Pairs Permitted There are two parts to this assignment, one on programming in Haskell and a set of written questions about laziness. There is no Scheme programming (and hence no jousting component) for this assignment. Part 1: Haskell ProgrammingThe Haskell Notes page provides pointers to language manuals and a mapping from common Scheme functions to their Haskell equivalents.Problem 1: Prime Numbers 1. Write isPrime :: Integer -> Bool, which determines whether a given integer is prime. 2. Define primes :: [Integer], the list of all primes. 3. If your initial isPrimechecks divisibility by all factors, write a second version isPrime2that only tests divisibility by primefactors. (If your original definition did this, you don't need to submit anything for this part.) Problem 2: Longest Common Subsequence 1. Write buildList :: Int -> (Int -> a) -> [a], where ((buildList n f) !! i) == (f i)(for all i in [0 .. n-1]). 2. Write buildTable :: Int -> Int -> (Int -> Int -> a) -> [[a]], where (((buildTable n m f) !! i) !! j) == (f i j)(for all i in [0 .. n-1], j in [0 .. m-1]). 3. Write lcs :: String -> String -> String, which computes the longest common subsequence of two strings s1 and s2. Characters in subsequences need not be consecutive in the original word, but they must occur in order. For example, lcs "baseball" "fable"should be "abl". If a world has two subsequences of the same maximal length, return either one. A good solution to this will exploit laziness and compute the value for an expression only once. The buildTable function will help with the latter. Regarding the former, your submitted solution (WPI)-H3/CS4536/Homework/hwk3.html (1 of 5) [2/6/2008 12:01:51 PM]
This preview
has intentionally blurred sections.
Sign up to view the full version.