Advanced Functional Programming TDA342/DIT260 (Mocked Online Exam)
Date | Sunday, 15 March 2020 |
Time | Sunday, 15 March 2020, 15:00 - Wednesday, March 18 2020, 18:00 |
Submission window | Wednesday 18 2020, 18:00 - 18:10 |
Preliminaries
Remember to take ten minutes to submit your online exam. There is a submission window (12:30 - 12:40), but if you finish the exam before, you can submit it as you did when submitting regular assignments ahead of time.
The maximum amount of points you can score on the exam: 60 points. The grade for the exam is as follows:
- Chalmers students:
- 3: 24 - 35 points
- 4: 36 - 47 points
- 5: 48 - 60 points
- GU students:
- Godkänd: 24-47 points
- Väl godkänd: 48-60 points
- PhD student: 36 points to pass.
- Chalmers students:
Results will be available within 21 days from the exam date.
Notes:
- Read through the exam first and plan your time.
- Answers preferably in English, some assistants might not read Swedish.
- If a question does not give you all the details you need, you may make reasonable assumptions. Your assumptions must be clearly stated. If your solution only works under certain conditions, state them.
- As a recommendation, consider spending around 1h 20 minutes per exercise. However, this is only a recommendation.
- To see your exam: by appointment (send email to Alejandro Russo)
Preliminaries about this online exam
Please note that this is an exam to be carried out individually, and since this is an exam from home, we will be very strict with plagiarism.
This exam considers that you will have open books as well as Internet access, i.e., access to the course's content and code, Hoogle, etc. -- and you can use all of such resources!
The exam consists on programming exercises and multiple questions.
- You will get a source code skeleton for each coding exercise that you need to complete.
- Each question is to be answered as a comment in your source code. There are specific places in the source code indicating where to write your answer.
The exam is designed to not need any special Haskell package. It is enough to use the ones imported by each source file.
What and how to submit
You should submit the code skeleton completed with your solution and answers. The code skeleton can be found below.
Code skeleton (Check Files tab) mocked-exam-0.1.0.0.tar.gz Before you submit your code, please clean it up! We will use the same requirements for clean code as in the course's assignments, that is, clean code
- does not have long (> 80 characters) lines
- has a consistent layout
- has type signatures for all top-level functions
- has good comments for all modules, functions, data types and instances.
- has no junk (junk is unused code, code which is commented out, unnecessary comments)
- has no overly complicated function definitions
- does not contain any repetitive code (copy-and-paste programming)
Use
cabal sdist
to generate the source tarball that you will submit. Make sure the tarball is working by extracting it in another directory and runningcabal configure
andcabal build
and checking that everything looks right.In addition, submit the files
Ex1.hs
,Ex2.hs
, andEx3.hs
with your solutions and answers in Canvas and make sure that they are not part of any directory/folder, i.e., we want just plain.hs
files. This helps us to grade your submission fast since Canvas does not understand.tar.gz
files.
Exercise 1 (20 points)
File src/Exam/Ex1.hs
You have seen before the Haskell function
reverse :: [a] -> [a]
In this exercise, we will explore a bit more.
Task 1 (10 pts)
Implement the function
freverse :: [a] -> [a]
which simply implements
reverse
usingfoldr
.foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
Question: Is
freverse
faster than Haskellreverse
? Justify your answer.
Task 2 (10 pts)
Write a Quick Check property that test that your function, freverse
behaves
the same as Haskell's reverse
.
Exercise 2 (20 points)
File src/Exam/Ex2.hs
It is often very useful to take the last element of a list.
Task 1 (20 pts)
Using function freverse
from the previous exercise, write a function which
takes the last element of a list:
myLastElem :: [a] -> a
Exercise 3 (20 points)
File src/Exam/Ex3.hs
Monad are very cool abstractions.
Given the following data type definition:
data X a = X a
Task 1
Give the instance
Monad
forX
as the identify monad.Can you give instances for
Applicative
andFunctor
using the methods fromMonad
? Justify your answer.