4.12 Fundamentals of Functional Programming Flashcards

(15 cards)

1
Q

What is a function

A

a rule for each element in some set A of inputs (domain), assigns an output chosen from set B (co-domain), but without necessarily using every member

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

How does a function work

A

An argument is passed to a function, the rule is applied to the argument, creating the return value output

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

What is a higher-order function

A

a function that takes a function as an argument or returns a function as a result, or does both

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

what are first class objects

A

objects which may
- appear in expressions
- be assigned to a variable
- be assigned as arguments
- be returned in function calls

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

what are some first-class objects

A

integers, floating-point values, characters, strings and functions

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

what does a function being a first class object mean

A

it can be passed as arguments or returned as the result of another function

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

what does function application mean

A

giving particular inputs to a function

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

what is a 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
9
Q

what is meant by composition of functions and the benefit

A

combines two functions to create a new function - users are able to use the function both separately and in conjunction

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

criteria for functions that can be combined

A

the domain of one of the functions is the same as the co domain of the other

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

what order would you do these functions in g ○ f

A

f is applied first and then g is replied to the result

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

what is the map function

A

it is a higher-order function that applies a given function to each element of a list, returning a list of results

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

what is the filter function

A

a higher-order function that processes a data structure, typically a list, in some order to produce a new data structure containing exactly those elements of the original data structure that match a given condition

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

what is the reduce or fold function

A

a higher order function which reduces a list of values to a single value by repeatedly applying a combining function to the list values

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

describe the head and tail of
a list and what is the head and tail of the list [3,4,5]

A

head - first value of the list - 3
tail - list containing all values except for the first element - [4,5]

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