BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

Haskell代写|Quiz: Mock Midterm

Haskell代写|Quiz: Mock Midterm

本次美国代写是一个Haskell的限时测试

Question 2

Which of the following is not a valid expression in this grammar:

<EXPR> = ‘0’
| ‘1’
| ‘(‘ <EXPR> ‘+’ 1 ‘)’

  • 1
  • (((1 + 1) + 1) + 1)
  • (((0 + 0) + 1) + 1)
  • (1 + 1)
  • ((0 + 1) + 1)
  • All of the above are valid expressions in the grammar

Question 3

Which of the following is true about the lambda-calculus?

  • It is impossible to write recursive functions in the lambda-calculus.
  • It is impossible to have non-terminating expressions in the lambda-calculus.
  • It is possible to write an interpreter for the lambda-calculus in Python.
  • All of the above are true.
  • None of the above are true.

Question 4

Fill in the BLANK in this Racket function that checks if the length of the list is odd.

(define (odd-items? lst)
(if (empty? lst)
#f
BLANK))

  • (not (odd-items? (rest lst)))
  • (cons (first lst) (odd-items? (rest lst)))
  • (odd-items? (rest lst))
  • (and (odd-items? (first lst)) (odd-items? (rest lst)))
  • (append (first lst) (odd-items? (rest lst)))

Question 5 

Suppose we have the following definition of the Haskell function f. Will the semantics of the
function change if we swap lines 1 and 2? What about lines 2 and 3?

1. f 0 = 0
2. f 1 = -1
3. f x = x

  • No change if we swap lines 1 and 2; No change if we swap lines 2 and 3.
  • No change if we swap lines 1 and 2; Yes if we swap lines 2 and 3.
  • Yes if we swap lines 1 and 2; No change if we swap lines 2 and 3.
  • Yes if we swap lines 1 and 2; Yes if we swap lines 2 and 3.

Question 6

Is this Haskell function tail recursive?

g [] lst2 = lst2
g lst1 [] = lst1
g (x:xs) lst2 = x:(g xs lst2)

  • Yes
  • No
bestdaixie

评论已关闭。