Functional Programming (H) - 1.05
1. What is the difference between an expression and a statement in an imperative programming language
Expressions determine control flow and are often composed of statements
Expressions denote small scale computations that return a value
Statements handle sequencing, looping, conditionals, and all the large scale operation of a program
2. What is the result of the following expression in Haskell, where sqrt returns the square root of its argument:
sqrt 16+9
13
5
3. What is the result of the following expression in Haskell, where sqrt returns the square root of its argument:
sqrt (16+9)
5
13
4. Give one reason why the following code is incorrect in Haskell:
x = 4 x = ((x * 2))
Because there are too many parentheses
Because you can assign an expression to a name only once
5. What is the result of the expression
abs -6
in Haskell, where abs returns the absolute value of its argument.
An error
6
6. In Haskell, what is another appropriate name for this style of expression:
n = n + 1
An equation
An assignment
7. Is it valid to write
n = n + 1
in Haskell
No, it is a syntax error
Yes, it is a valid expression
Submit Quiz