Skip to content
This repository was archived by the owner on Mar 9, 2025. It is now read-only.

CS208/hw3-haskell

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Hw3 Haskell

Question 1

Write the following functions in Haskell and provide a few test cases.

Part 1

The pre-defined procedures min and max each take two arguments and return the smallest/largest of the two, or the first argument if they are both equal. a. Define lmin and lmax which apply these functions to lists of numbers using min and max b. Define lmin and lmax without using min and max.

Part 2

Implement deepSum, where given an instance of Nested, defined below, an arbitrarily nested list of numbers, deepSum the sum of all the numbers. That is, your input list may have sublists, which may themselves have sublists and so on.

data Nested a = Value a | List [NestedList a]

Which can be instantiated as follows:

x = (List [Value 3, List [Value 2, Value 3], Value 4])

Implement deepsum on an instance of Nested instead of arbitrarily nested lists. a. Haskell has stricter type requirements than Scheme did. What would be true of nested arrays in Haskell? b. Implement the function

Question 2 - Prime numbers

Write a function with the signature Int -> [Int] which returns the first k prime numbers. You may need to implement multiple functions to make this work. Try to make it as efficient as possible (ie, as few unnecessary computations as possible). Implement this problem in a separate file.

Question 3

Implement mergeSort in Haskell. What kinds of values can your function sort?

Question 4

nsum L n takes in a list L and a number n and returns a resulting list where the i th element is the sum of the elements from position i to min (length L) (i + n). For example nsum [2, 3, 12, 4] 3 => [17, 19, 16, 4] Implement nsum

About

Haskell Problem set 1

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors