chinese food 2

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/39

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

40 Terms

1
New cards

What is the main reduction rule of the semantic of the λ-calculus?

B-reduction

2
New cards

A list [1,2,3] in Haskell is syntactic sugar for…

1 : 2 : 3 : [] wwhich is equivalent to 1 : (2 : ( 3 : []))

3
New cards

Which kind of recursion is an important concept in functional programming?

tail recursion

4
New cards

What does it mean that Haskell is a pure functional programming language?

the evaluation of expressions has no side-effects

5
New cards

What language feature is not a feature of haskell?

mutable variables

6
New cards

Which technique can be used to transform a recursive function into an equivalent tail recursive function?

Accumulating parameters

7
New cards

In the haskell function definition

product [] = 1
product (x:xs) = x * product xs

pattern matching

8
New cards

Which haskell language feature is used wwhere other languages would use NULL pointers?

algebraic data types, in particular co-products

9
New cards

What makes a recursive function definition tail recursive?

it contains exactly one recursive call and its return value is immediately returned by the calling function

10
New cards

Which of the following expressions is not equivalent to the section (^2)

\x → 2^x

11
New cards

Evaluate the expression
a’b’c
where
a = “a”
b = (++)
c = “c”

“ac”

12
New cards

Evaluate the following haskell fold expression:

foldr (+) 0 [1, 2, 3]

6

13
New cards

Evaluate the following Haskell fold expression:


foldr (-) 0 [1, 2, 3]

2

14
New cards

Evaluate the following Haskell fold expression:

foldl (+) 0 [1, 2, 3]

6

15
New cards

Evaluate the following Haskell fold expression:

foldl(-) 0 [1, 2, 3]

-6

16
New cards

Evaluate the following Haskell fold expression:

foldr (+) 5 [1, 2, 3]

11

17
New cards

Evaluate the following Haskell fold expression:

foldl (-) 5 [1, 2, 3]

-1

18
New cards

What is the type of the following polymorphic Haskell function? max a b = if a <= b

max a b = if a <= b then b else a

max : : Ord a => a → a → a

19
New cards

What is the type of the following polymorphic Haskell function? head (x:xs) = x

head (x:xs) = x

head : : [a] → a

20
New cards

What is the type of the following polymorphic Haskell function?

length [] = 0
length (a:as) = 1 + length as

length : : Num n => [a] → n

21
New cards

What is the type of the following polymorphic Haskell function?
maximum = foldll max
where
max a b = if a <= b then b else a
and where foldll is the following function from Data.List:
foldll : : Foldable t => (a → a → a) → t a → a

maximum : : (Foldable t, Ord a) => t a → a

22
New cards

Consider the Haskell function definition
const x _ = x
Evaluate
const (1+) 10 100

101

23
New cards

Consider the Haskell function definition
const x _ = x

What is the type of const?

const : : a → b → a

24
New cards

Consider the Haskell function definition
const x_ = x

Evaluate the Haskell expression
foldr (const (1+)) 0 [2, 31, 1]

3

25
New cards

Consider the Haskell function definition
const x _ = x
Evaluate the Haskell expression
foldl (const (1+)) 0 [2, 3, 1]

2

26
New cards

Consider the haskell function definition
(++) [] ys = ys
(++) (x:xs) ys = x: (xs++ys)
Evaluate the Haskell expression “c” “++” “++”

“c++”

27
New cards

Consider the haskell function definition
(++) [] ys = ys
(++) (x:xs) ys = x: (xs++ys)

What is the type of (++)?

(++) : : [a] → [a] → [a]

28
New cards

Consider the haskell function definition
(++) [] ys = ys
(++) (x:xs) ys = x: (xs++ys)

What does the function foldr (++) [] do?

flatten a list of lists

29
New cards

Consider the Haskell function
flip f a b = f b a
Evaluate flip (-) 1 2

1

30
New cards

Consider the Haskell function
flip f a b = f b a
What type is flip?

flip : : (a→b→c) → (b→a→c)

31
New cards

Consider the Haskell function
flip f a b = f b a
Evaluate the expression
foldl (flip(:)) [] “drawer”

“reward”

32
New cards

Consider the Haskell data type and function definitions: data (a,b) = (a,b)

fst (a, _) = a
snd (_, b) = b
which kind of algebraic data type is (a, b)?

a product

33
New cards

Consider the Haskell data type and function definitions: data (a,b) = (a,b)

fst (a, _) = a
snd (_, b) = b
What kind of functions are fst and snd?

projections

34
New cards

Consider the Haskell data type and function definitions: data (a,b) = (a,b)

fst (a, _) = a
snd (_, b) = b

Evaluate the expression
let f p = fst p - snd p in f(1, 3)

-2

35
New cards

Consider the following Haskell function definitions:
foldr _ z [] = z

foldr f z (x:xs) = f x (foldr f z xs)

foldl _ z [] = z
fold f z (x:xs) foldl f (f z x) xs

Which of these functions are tail recursive?

foldl but not foldr

36
New cards

Consider the following Haskell function definitions:
foldr _ z [] = z

foldr f z (x:xs) = f x (foldr f z xs)

foldl _ z [] = z
fold f z (x:xs) foldl f (f z x) xs

What is the type of foldr?

foldr : : (a→b→b) →b → [a] → b

37
New cards

Consider the following Haskell function definitions:
foldr _ z [] = z

foldr f z (x:xs) = f x (foldr f z xs)

foldl _ z [] = z
fold f z (x:xs) foldl f (f z x) xs

What is the type of foldl?

foldl : : (b→a→b) → b → [a] → b

38
New cards

Consider the following Haskell data type definition: data Maybe a = Nothing | Just a

What can Maybe be used for?

optional values

39
New cards

Consider the following Haskell data type definition: data Maybe a = Nothing | Just a

instance Foldable Maybe
wwhere
foldr _ z Nothing = z

foldr f z (Just x) = f x z

and keep in mind that functions like
sum : : (Foldable t, Num a ) => t a → a
are defined in terms of foldr.

Evaluate the expression sum Nothing

0

40
New cards

Consider the following Haskell data type definition: data Maybe a = Nothing | Just a

instance Foldable Maybe
wwhere
foldr _ z Nothing = z

foldr f z (Just x) = f x z

and keep in mind that functions like
sum : : (Foldable t, Num a ) => t a → a
are defined in terms of foldr.

Evaluate the expression sum (Just 2)

2