4.12: section 12: OOP and functional programming Flashcards

1
Q

define function application

A

process of giving particular inputs to a function

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

what is function type

A

f: A ->B

f = function
A = argument type: set of inputs =domain
B = result type
set of outputs = co-domain

A and B must be subsets of objects in some data type

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

how many arguments can functions take

A
  • although it seems multiple functions are being passed through only 1 is actually being applied
  • instead the result and function are passed as inputs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

define partial function application

A

takes advantage of the inability of a function to take more than one input

-one of the arguments is fixed leading to a more restricted specialized function

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

define composition functions

A

operation functional composition combines 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 is a high order function

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 is the map function

A

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 is a 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
9
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.

-can be started from the left or right of the list

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

what is the head and tail of a list

A

head: first element in a list
tail: all remaining elements

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

how do you return the head of a list

A

head list_Name

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

how do you return the tail of a list

A

tail list_Name

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

how do you test for a empty list

A

null list_Name

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

how do create an empty list

A

list_Name = []

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

how do you return a list length

A

length list_Name

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

how do you prepend an item to a list

A

newValue: list_Name

or

[newValue] ++list_Name

this doesnt change the list but instead cretaes a new one as the values are immutable

17
Q

how do you append an item to a list

A

list_Name ++ [newValue]

or

create a function that reverses the list, prepends the value and reverses the list again

let append y (x:xs) = reverse(y:reverse(x:xs))