Homework 3: Haskell and Laziness

Homework 3 Haskell - CS 4536 Haskell and Laziness Assignment CS 4536 Homework 3 Haskell and Laziness Due Thursday:59pm via turnin(assignment name

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 4536 - Haskell and Laziness Assignment CS 4536 Homework 3: Haskell and Laziness Due: 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 Programming The 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 isPrime checks divisibility by all factors, write a second version isPrime2 that only tests divisibility by prime factors. (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 file:///C|/Documents%20and%20Settings/Linda%20Graue. ..ic%20Institute%20(WPI)-H3/CS4536/Homework/hwk3.html (1 of 5) [2/6/2008 12:01:51 PM]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 4536 - Haskell and Laziness Assignment should not simply generate all possible subsequences from all pairs of indices then look for the longest (though if writing the code this way first helps you get a feel for the problem, feel free). Your code should only generate instances of the lcs problem that are necessary to compute the longest subsequence. As a hint, you could try computing
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This homework help was uploaded on 02/06/2008 for the course CS 4536 taught by Professor Fisler during the Winter '08 term at WPI.

Page1 / 5

Homework 3 Haskell - CS 4536 Haskell and Laziness Assignment CS 4536 Homework 3 Haskell and Laziness Due Thursday:59pm via turnin(assignment name

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online