4.12 - Fundamentals of functional programming Flashcards

1
Q

What is a function?

A

A rule that, for each element in some set A of inputs, assigns an output chosen from set B, but without necessarily using every member of B.

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

What is an argument?

A

A piece of data passed into a function.

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

What is a first class object?

A

An object which may:
- Appear in expressions
- Be assigned to a variable
- Be assigned as an argument
- Be returned in function calls

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

What are functions in functional programming?

A

First-class objects

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

What is function application?

A

Applying a function rule to the arguments of the function

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

What is partial function application?

A

One of the arguments is fixed, leading to a more restricted specialised function.

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

What is composition of functions?

A

The act of combining two functions to create a new function. User is able to use functions both separately, and in conjunction. Domain of one must be same as co-domain of the other.

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

What are higher order functions?

A

Either take function as an argument, return function as a result, or both.

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

What does the map function do?

A

Takes a second function and applies it to a list of elements before returning the new list.

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

What does the filter function do?

A

Returns elements of a list which adhere to condition given.

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

What does the fold function do?

A

Reduces list to a single value. It needs an operator (+,- etc), a starting number, and a list. The type of fold (left or right) determines how the recursion will work.

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

What does the prepend operator do?

A

It has the symbol : and is used to add items to the front of a list.

It is used in the format
item : list

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

What does the append operator do?

A

It has the symbol ++ and is used to add items to the rear of a list.

It is used in the format
item ++ list

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

How do you find if a list is empty?

A

null listname

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

How do you find the length of a list?

A

length listtname

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

How do you find the nth item of a list?

A

listname !! n

(indexing starts at 0)