4.12 Fundamentals of Functional Programming Flashcards

1
Q

What is meant by first class objects

A

are 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
2
Q

What is meant by function application

A

The process of giving particular inputs to a function

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

What is the domain and co domain of a function

A

domain - a set from which the function’s input values are chosen.

codomain - a set from which the function’s output values are chosen

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

What is partial function application

A

Partial function application is a concept where a function that takes multiple arguments is applied to some of its arguments, resulting in a new function that takes the remaining arguments.

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

What is composition of functions

A

Combing two functions to get a new function

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

What are Higher-order functions.

A

A function is higher-order if it 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
7
Q

what does the map function do

A

map is the name of 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
8
Q

what does the filter function do

A

filter is the name of 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
9
Q

what does the reduce or fold function do

A

reduce or fold is the name of 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
10
Q

How do functional programmers define lists

A

As a concatenation of a head and a tail

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

what is the head of a list

A

Head: The first element of the list.

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

what is the tail of a list

A

Everything after the first element — the rest of the list.

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

How do you return the head of list

A

use of index, eg, print list[0]

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

How do you return tail of list

A

tail = list[1:]

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

How do you test for empty list

A

use len function

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

How do you return length of list

A

use len function

17
Q

How do you construct an empty list

18
Q

How do you prepend an item to a list

A

new_list = [1] + list

19
Q

How do you append an item to a list.

A

list.append(value) or list.extend(value)

20
Q

Haskell and Lisp are both types of what programming paradigm?

A

functional programming languages.

21
Q

If the domain of the function below is {1, 2, 3}, what is the co-domain?

func x = x * 3

22
Q

what is meant by a variable that is immutable?

A

Variables cannot be reassigned once they are given a value

23
Q

Functional programming is stateless and has no side effects. what does this mean?

A

The state of memory does not change, i.e. the values of variables stay the same. Therefore there is no record of previous operations and each operation is processed using only the arguments/parameters provided will always return the same result for a given input and so cannot affect other operations within the program.

24
Q

what does 5:[1,2,3] do in haskell

A

creates a new list with 5 at the front

25
what does [1,2] ++ [3,4]
creates a new list comprised of those two lists
26
What is the result of this program? foldr (-) 100 [3,4,5,6]
98
27
What is the result of this program? foldl (-) 100 [3,4,5,6]
82