Functional programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What type of functions does functional programming use?

A

Pure functions (Do not modify data, do no use variables, no function shares data with any other function)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is functional programming useful for?

A
  • Machine learning

- Processing big data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name some higher order Haskell functions

A
  • map
  • filter
  • fold
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In (f: A → B), what part is the domain?

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In (f: A → B), what part is the codomain?

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Declared values or expressions are immutable. What does immutable mean?

A

Immutable means that they can’t be changed during program execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Name some examples of base types in Haskell (must be written with a capital)

A
  • Integer
  • Float
  • Double
  • Bool
  • Char
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What class object is a function?

A

A function is a first class object which can be an argument to another function as well as the result of another call.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is function application?

A

Applying a function to its arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is partial function application?

A

Applying part of a function to its arguments, splitting them up using brackets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is composition of functions?

A

Combining two functions together (indicated using a small circle ∘)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is required for function composition to work?

A

The codomain of f must match the domain of g

g ∘ f: A -> C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How is function composition represented in Haskell?

A

(A.B)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a higher order function?

A

a function that takes one or more functions as arguments and/or returns a function as its result. (map, filter, fold)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the ‘map’ higher order function do in Haskell?

A

Applies a function to every element in the list.
> map (^2) [20, 3, 51, 6, 3, 7]
[400, 9, 2601, 36, 9, 49]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the ‘filter’ higher order function do in Haskell?

A

Filters a list based on criteria.
> my_list = [1,2,3,4,5,6,7,8,9]
> filter (>5) my_list
[6,7,8,9]

17
Q

What does the ‘fold’ higher order function do in Haskell?

A

Adds each element in the list from left to right (or right to left depending on if the command is foldl or foldr)
> my_list = [1, 2, 3, 4]
> foldl (+) 0 my_list
10

18
Q

What is the head of a list?

A

The number at the start

19
Q

What is the tail of a list?

A

Every number which isn’t the head

20
Q

How do you find the length of a list in Haskell?

A

Input: length [1,2,3]
Output: 3

21
Q

How do you reverse a list in Haskell?

A

reverse xs

22
Q

How do you get the Nth element out of a list in Haskell?

A

xs !! n

23
Q

How do you prepend an element to a list in Haskell?

A

: