Understand the functional model in which a program is a set

Post New Homework

CP50065E Functional Programming - University of West London

Learning outcome 1: Understand the functional model in which a program is a set of nested expressions.
Learning outcome 2: Design recursive functions using base and recursive cases.
Learning outcome 3: Understand the main features of a lazy functional language.
Learning outcome 4: Write, understand and analyse functional programs in Haskell.

The assessment consists of two elements:

- For element 1, implement a number of functions and write a short report about your submission.
- For element 2, implement an application and write a short report about your submission.
For each of the two elements, you need to submit a zip file with the source code and one report (as pdf or Word/doc/docx file).
For the source code submission, please note the following:
1. Any code you write must be in Haskell and follow the functional programming paradigm.
2. Your code should be correct, maintainable and readable:
a. Identifiers should have reasonable names hinting and their purpose or function.
b. Code should be reasonably commented:
i. Module files should have a brief outline summarising their contents.
ii. Any non-trivial function should have its purpose explained and arguments listed, including their semantics.
iii. Use of whitespace (tabulators, empty lines, etc.) should be conducive to reading the code.
3. All code in your solutions must be your own. Unless otherwise specified, you can use the full standard prelude, but not any external modules, libraries, packages, or similar, even when these were mentioned in the lecture material or further reading. Unless otherwise mentioned, all modules imported in your code must be your own.
4. You can develop your submission in whatever environment you like (Windows, Macintosh, Linux, you name it), but a common standard is necessary. Therefore, it is a significant requirement that your submission executes correctly on a clean WinGHCi installation as installed on the university computers, without any modifications or additions either to your code, or to the WinGHCi installation. Remote access to the university's WinGHCi installation is available via AppsAnywhere.
5. Some parts of the assessment stipulate strict submission structure (module elements, function arguments, class members, etc.) and identifier values (e.g., names for files, folders, functions, classes, class members, etc.). Meeting these requirements to the letter forms a significant part of the grade.

For the report submission, please note the following:

1. Keep your reports succinct and to the point. Include in the reports what the assessment asks you to include - not more, not less. Do not repeat the task in the reports.

Element 1 - Portfolio module

Task details Implement a module containing four functions and write a short report about your implementation:
Function 1: Return a list of all prime numbers up to a given limit:
A positive integer is a prime number if it is evenly divisible only by itself and 1. Using a list comprehension, define a function
primes_<your_student_number> :: Int -> [Int]
that returns the list of all prime numbers up to a given limit. For example:
primes_<your_student_number> 10
would return
[2,3,5,7]
Function 2: Encrypt text using Caesar's cipher
The Caesar Cipher is one of the earliest and simplest methods of encryption. It's a type of substitution cipher, i.e., each letter of a given text is replaced by a letter some fixed number of positions down the alphabet. You can assume that the plain text will contain alphanumerical characters only, i.e., it will contain (in that order)
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 "
Take note of the space character at the end.
For example, with a shift of 1, occurrences of a are replaced by b, occurrences of b are replaced by c, and so on: z is replaced by A, Z is replaced by 1, 1 is replaced by 2, 0 is replaced by the space character, and the space character is replaced by a. With a shift of 2, occurrences of a are replaced by c, occurrences of b are replaced by d, and so on.
You can assume that the plain text will contain alphanumerical characters and spaces only.
Thus, to cipher a given text we need an integer value, known as shift, to indicate the number of position each letter of the text has been moved down. The method is named after Julius Caesar, who historically used it to communicate with his officials.
Define a function
caesarcipher_<your_student_number> :: [Char] -> Int -> [Char]
that take a plain text and a shift, and returns the corresponding cipher text. For example:
caesarcipher_<your_student_number> "Veni vidi vici" 2
would return
"Xgpkbxkfkbxkek"
Function 3: Implement the factorial function
Using recursion, define a function
factorial_<your_student_number> :: Int -> Int
calculating the factorial of a number, that is, the product of all positive integers less than or equal to the given number.
For example:
factorial_<your_student_number> 5
would return
120
Function 4: Merge two sorted lists
Define a recursive function
merge_<your_student_number> :: Ord a => [a] -> [a] -> [a] that merges two sorted lists to give a single sorted list. For example: merge_<your_student_number> [2,5,6] [1,3,4]
would return
[1,2,3,4,5,6]
Note: Your definition should not use other functions on sorted lists such as insert or isort, but should be defined using explicit recursion.

Report
Write a short report (less than 1000 words). For each of the four functions above, the report needs to include a screenshot of the function as executed, and detail how functional programming concepts were applied.
The report should also include a brief overall reflection of what went well, what did not go well, and what you would do differently if you were given a similar task in the future.

Attachment:- Functional Programming.rar

Post New Homework
Captcha

Looking tutor’s service for getting help in UK studies or college assignments? Order Now