Section 12 - Functional programming Flashcards

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

What is a programming paradigm?

A

A style of computer programming

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

What are the 4 types of programming paradigms?

A
  • Procedural programming
  • Object-orientated programming
  • Declarative programming
  • Functional programming
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is procedural programming?

A

Where a series of instructions tells the computer what to do with the input in order to solve the problem

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

What is structured programming?

A

A form of procedural programming which uses the modular techniques to split large programs into manageable chunks

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

What programming constructs does structured programming use?

A
  • Sequence
  • Selection
  • Iteration
  • Recursion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is object-orientated programming?

A

A programming paradigm comprised of classes of objects. It is was developed to make it possible to abstract details of implementation away from the user, making code reusable and programs easy to maintain

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

What is declarative programming?

A

Where you write statements the describe the problem to be solved, with the language implementation deciding the best way to solve it

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

What is functional programming?

A

Functions are used as the fundamental building blocks of a program, where statements are written as a series of functions which accept input data as arguments and return an output

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

What is a function?

A

A mapping from the domain to the co-domain

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

What is the domain?

A

The set of inputs

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

What is the co-domain?

A

The set of possible outputs

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

What is always true about the domain and co-domain?

A

They are always subsets of objects in some data type

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

What is Haskell?

A

A functional programming language

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

What is a parameter in Haskell?

A

A reference declared in a function declaration

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

What is an argument in Haskell?

A

A value or expression passed to a function

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

What is 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
17
Q

What are first-class objects?

A

An object that can:
- Appear in expressions
- Be assigned to a variable
- Be assigned as an argument
- Be returned in a function call

18
Q

What is unique about variables in functional programming?

A

The value of a variable is immutable and the program is stateless

19
Q

What is referential transparency?

A

A function that is called twice with the same parameters will always return the same result

20
Q

What is the advantage of referential transparency?

A

It is relatively easy to write correct, bug free programs

21
Q

What does it mean to have no side effects?

A

The only thing a function can do is calculate something and return a result so it has no side effects

22
Q

What is functional composition?

A

Combining 2 functions to get a new function, by using a function as an argument

23
Q

What are types?

A

Sets of values

24
Q

What are typeclasses?

A

Sets of types

25
Q

What is a type variable?

A

A variable that represents any type

26
Q

What is a higher order function?

A

A function that either takes a function as an argument or returns a function as a result

27
Q

How many arguments can a function in Haskell take?

A

Only 1, because each argument will result in a new function being created

28
Q

What is partial function application?

A

Fixing the values of some inputs to a function in order to produce another more specific function

29
Q

What is the map function?

A

A higher-order function that takes a list, treats each element as an input and applies the function to each element, returning a new list

30
Q

What is a list?

A

A collection of elements of the same type, enclosed in square brackets

31
Q

What is the max function?

A

A built-in library function that returns the maximum of 2 numbers

32
Q

What is the filter function?

A

A higher-order function that takes a predicate and a list, returning the elements within the list that satisfies the Boolean condition

33
Q

What is a predicate?

A

A boolean condition

34
Q

What is a fold function?

A

A higher-order function that reduces a lost to a single value via recursion

35
Q

What is the difference between foldl and foldr?

A

Foldl has the recursion starting at the leftmost value, Foldr has the recursion starting at the rightmost value

36
Q

What is the head of a list?

A

The first element in the list

37
Q

What is the tail of a list?

A

The last element in the list

38
Q

Can lists be modified?

A

No, they are immutable

39
Q

What does the function null do?

A

It tests for an empty list

40
Q

What is prepending?

A

Adding an element to the front of the list

41
Q

What is appending?

A

Adding an element to the end of a list