0/23 Questions Answered
Mid-Semester Exam I Repeat
STUDENT NAME
Search students by name or email… ” Q1 Instructions
0 Points
You must acknowledge the following integrity pledge before proceeding. Please read carefully and check all the boxes.
I am committed to being a person of integrity.
I pledge, as a member of the Australian National University community, to abide by and uphold the standards of academic integrity outlined in the ANU statement on honesty and plagiarism, and I am aware of the relevant legislation, and understand the consequences of me breaching those rules.
I will not actively communicate in any way with anyone else during this exam. This includes asking questions in any online forum.
Read and check off the following instructions:
1. You will need to be able to upload code files to this browser from your Haskell workspace. You must also make sure all code you upload compiles without errors.
Make sure this browser window is open on the machine where you plan to work.
If you are working on the ANU Linux VDI this browser window should be open in Linux, not on your personal machine.
If this browser window is not open where you plan to work close this window now and log back into the exam in a browser on your work machine.
2. This examination is timed.
Note the remaining time at the top right of this screen. Set an alarm for yourself if you need one.
3. Permitted materials. This is an open book exam. You might in particular find the course website, the Prelude documentation, and the Data.List documentation useful.
You may use any documentation you wish but all work must be your own.
Save Answer
Q2 Commands 2 Points
What does the Linux shell command cd do? # List files in a folder
# Creates a new folder
# Changes the current folder
# Copies a folder Save Answer
Q3 Number Systems 4 Points
Consider the expression
102 + 1016 + 1010
where the subscript denotes the base of a numbering system.
For each of the following select True if the equality holds and False otherwise.
Each correct answer gains you 1 point while each incorrect answer loses you 0.5 point. An unanswered question neither gains nor loses you points.
1. 102 + 1016 + 1010 = 2810 # True
# False
2. 102 + 1016 + 1010 = 3010 # True
# False
3. 102 + 1016 + 1010 = 1C16 # True
# False
4. 102 + 1016 + 1010 = 111002 # True
# False
Save Answer
Q4 Problem Classes 2 Points
Given a quadratic equation ax2 + bx + c = 0 classify the problem of finding the existence of real solutions into one of the four problem classes:
# Functional problems # Decision problems
# Search problems
# Optimisation problems
Save Answer
Q5 Sets 3 Points
Given C = {heads, tails}, and W = {sunny, rainy, snowy}, which one of the following is the set C × W ?
# {(heads, 1), (tails, 1), (sunny, 2), (rainy, 2), (snowy, 2)} # {(heads, sunny), (heads, rainy), (heads, snowy),
(tails, sunny), (tails, rainy), (tails, snowy)}
# {heads + sunny, heads + rainy, heads + snowy, tails + sunny, tails + rainy, tails + snowy}
# {(heads, heads), (tails, tails),
(sunny, sunny), (rainy, rainy), (snowy, snowy)}
# {(heads, 1), (tails, 2), (sunny, 3), (rainy, 4), (snowy, 5)} # {(heads, tails), (sunny, rainy, snowy)}
Save Answer
Q6 Sets 4 Points
Given B = {F,T}, which one of the following is the set B + (B × B)?
# {(F,F,F),(F,F,T),(F,T,F),(F,T,T), (T,F,F),(T,F,T),(T,T,F),(T,T,T)}
# {(F,F1),(F,T1),(T,F1),(T,T1),(F,F2),(F,T2),(T,F2),(T,T2)}
# {F1, F2, F3, T1, T2, T3}
# {F,T,(F,F),(F,T),(T,F),(T,T)}
# {(F,F,1),(F,T,1),(T,F,1),(T,T,1), (F,F,2),(F,T,2),(T,F,2),(T,T,2)}
Save Answer
Q7 Function Composition 4 Points
Recall that R is the set of real numbers, and B = {f alse, true} is the set of Boolean values.
Suppose we have functions minus :: R → R and isPos :: R → B.
For each of the following select True if the statement is correct and False otherwise.
Each correct answer gains you 1 point while each incorrect answer loses you 0.5 point. An unanswered question neither gains nor loses you points.
1. minus ∘ isPos is a valid function composition. # True
# False
2. isPos ∘ minus is a valid function composition. # True
# False
3. minus ∘ minus is a valid function composition. # True
# False
4. isPos ∘ isPos is a valid function composition. # True
# False
Save Answer
Q8 Haskell Lexical Names 5 Points
For each of the following, select True if the statement is correct and False otherwise.
Each correct answer gains you 1 point while each incorrect answer loses you 0.5 point. An unanswered question neither gains nor loses you points.
1. 1Fun is a legal function name. # True
# False
2. ‘fun1 is a legal function name. # True
# False
3. 1fun is a legal function name. # True
# False
4. _fun’1 is a legal function name. # True
# False
5. _$fun’1 is a legal function name. # True
# False
Save Answer
Q9 Function Definitions. 4 Points
For each of the following select True if it is a valid Haskell function definition and False otherwise.
Each correct answer gains you 1 point while each incorrect answer loses you 0.5 point. An unanswered question neither gains nor loses you points.
1. bmi = weight / height ^ 2 height = 1.80
# True # False
2. bmi = weight / height ^ 2 where weight = 80; height = 1.80 # True
# False
3. bmi = weight / height ^ 2
height = 1.80 # True
# False
4. bmi = weight / height ^ 2
where
weight = 80 height = 1.80 # True
# False
Save Answer
Q10 Expressions and Types 4 Points
For each of the following select True if it is a valid Haskell expression and False otherwise.
Each correct answer gains you 1 point while each incorrect answer loses you 0.5 point. An unanswered question neither gains nor loses you points.
1. 0 + True # True
# False 2. 3/5
# True # False
3. True && 1 # True
# False
4. 0.5*2
# True # False
Save Answer
Q11 Function Application 2 Points
Consider the following Haskell function definition:
mult :: (Int, Int) -> Int
mult (x, y) = x * y
Which of the following is a correct application of this function?
# mult (2, 3) # mult23
# mult 2
# (mult 2) 3 # mult (2 3)
Save Answer
Q12 Basic Types 5 Points
For each of the following select True if the statement is correct and False otherwise.
Each correct answer gains you 1 point while each incorrect answer loses you 0.5 point. An unanswered question neither gains nor loses you points.
1. ([],”abc”,[True]) is a value of type ([Int],[Char], [Bool]) .
# True # False
2. The type of [1,”12″, 2] is [Int, String, Int] . # True
# False
3. Type Bool is an instance of the Ord class. # True
# False
4. A list can have an infinite number of elements. # True
# False
5. New types can be declared using the keyword data . # True
# False
Save Answer
Q13 Control Structures 4 Points
Consider the following function definition:
foo n = n `mod` 2 == 0
For each of the following select True if it is an equivalent function
definition and False otherwise.
Each correct answer gains you 1 point while each incorrect answer loses you 0.5 point. An unanswered question neither gains nor loses you points.
1. foon=ifmodn2==0thenTrueelseFalse # True
# False
2. foon=casen`mod`2of
0 -> True
1 -> False
# True # False
3. foon=elemn[2*m|m<-[1..n]] # True
# False
4. foo 0 = True
foo n = bar (n-1)
bar 0 = False
bar n = foo (n-1) # True
# False
Save Answer
Q14 Lists 5 Points
For each of the following select True if the statement is correct and False otherwise.
Each correct answer gains you 1 point while each incorrect answer loses you 0.5 point. An unanswered question neither gains nor loses you points.
1. Lists can be constructed recursively using : . # True
# False
2. List [[2,2..2]] contains infinitely many elements. # True
# False
3. The length of the list [(x,y) | x <- a, y <- b] is the length of a multiplied by the length of b .
# True # False
4. Any two lists of the same type can be concatenated using ++ . # True
# False
5. The prelude function tail returns the last element of a given list.
# True # False
Save Answer
Q15 Lists 5 Points
Consider the following Haskell functions:
double lst = [2*n | n<-lst]
drop x xs = [n | n<-xs, (n/=x)]
For each of the following select True if the statement is correct and False otherwise.
Each correct answer gains you 1 point while each incorrect answer loses you 0.5 point. An unanswered question neither gains nor loses you points.
1. Functions double and drop are polymorphic. # True
# False
2. A possible type signature for double is [Int] -> [Int] . # True
# False
3. A possible type signature for drop is Int -> [Int] -> [Int] . # True
# False
4. The function composition double . drop 2 is well defined. # True
# False
5. foldr (&&) True (drop False xs) returns True for any legal list xs .
# True # False
Save Answer
Q16 Expressions 4 Points
Which of the following code fragments is a valid Haskell expression?
read “123” :: Double + (read “123” :: Double)
(read “123” :: Float) + read( show (read “123” :: Double))
(read “123” :: Float) + show (read “123” :: Float)
(read “123” :: Double) + read( show (read “123” :: Double))
Save Answer
Q17 Polymorphic functions 4 Points
For each of the following select True if the function has polymorphic type and False otherwise.
Each correct answer gains you 1 point while each incorrect answer loses you 0.5 point. An unanswered question neither gains nor loses you points.
1. swapxy=(y,x) # True
# False
2. double x = x * (2::Int)
# True # False
3. palindrome xs = reverse xs == xs # True
# False
4. twicefx=f(fx)
# True # False
Save Answer
Q18 Tuple Types 3 Points
Consider the following expression:
([False, True], “01”)
What is its type?
# ([Bool], [Char]) # (Bool, Char)
# (Bool, [Char]) # ([Bool], Char)
Save Answer
Q19 Computability 2 Points
Turing completeness refers to:
# Having branching constructions in the language.
# Having the capacity to iteratively execute block of code. # Being able to compute any algorithm.
# Being able to invoke functions.
# Allowing for recursion.
Save Answer
Q20 Haskell Programming 34 Points
The following programming questions use template files which you can access by clicking on the links in the questions below.
You must submit your answer using the link provided in each question to upload the file. You will not be able to push your solution to gitlab.
As an alternative to clicking on the links, you can clone the files from the gitlab repository at https://gitlab.cecs.anu.edu.au/comp1100/comp1100-2020S2-mse using the URL https://gitlab.cecs.anu.edu.au/comp1100/comp1100- 2020S2-mse.git with the command:
git clone https://gitlab.cecs.anu.edu.au/comp1100/comp1100-2020S2
Q20.1 Algebraic Data Types 8 Points
Click on the link Grocery.hs to download a Haskell script containing templates (instructions included) for the functions priceOf and
totalCost .
If your browser downloads the file as Grocery.hs.txt with the
extension .txt make sure to rename the file to Grocery.hs . You must complete both the functions priceOf and totalCost .
Make sure to edit and test using ghci before uploading using the following link:
$ Please select file(s) Select file(s) Save Answer
Q20.2 Recursion 8 Points
Click on the link Fact.hs to download a Haskell script containing a template (instructions included) for the function safeFact to compute factorial n! = 1 × 2 × 3 × 4 × … × n and return the result as a Maybe value. If n! is undefined for value n then return
Nothing .
If your browser downloads the file as Fact.hs.txt with the
extension .txt make sure to rename the file to Fact.hs . You must use recursion in completing the function safeFact .
Make sure to edit and test using ghci before uploading using the following link:
$ Please select file(s) Select file(s) Save Answer
Q20.3 Recursion on Lists 8 Points
Click on the link Take.hs to download a Haskell script containing a template (instructions included) for the function takeUntil to extract the prefix of a string up to (but excluding) the first occurrence of a given character.
If your browser downloads the file as Take.hs.txt with the extension .txt make sure to rename the file to Take.hs .
You must use recursion in completing the function takeUntil . Make sure to edit and test using ghci before uploading using the
following link:
$ Please select file(s) Select file(s)
Save Answer
Q20.4 Recursion on Lists 10 Points
Click on the link Remove.hs to download a Haskell script containing a template (instructions included) for the function removeAt to remove the character that appears at position n in a string, counting from 0.
If your browser downloads the file as Remove.hs.txt with the extension .txt make sure to rename the file to Remove.hs .
You must use recursion in completing the function removeAt . Make sure to edit and test using ghci before uploading using the
where
where
weight = 80
weight = 80
following link:
$ Please select file(s) Select file(s)
Save Answer
Save All Answers
Submit & View Submission !
-ms