Flashcards in Functional Programming Deck (32)

Loading flashcards...

1

##
What is a function type?

How would you write this?

###
It describes what the input and output values are.

E.g. inputting integers, outputting real numbers

Written like this: f: integer --> real (f: A --> B)

A is the argument type and B is the result type

2

## What could changing the function type do?

### The functionality could change without changing the instructions as different input values would be accepted.

3

## Explain each part of this f: A --> B

### F is the function name, A is the domain, B is the co-domain

4

## What is the definition of a function in functional programming?

### A rule that for each element in a set of inputs, assigns an output chosen from another set

5

## What is the definition of a domain in functional programming?

### A domain is a set from which a function's input values are chosen.

6

## What is the definition of a co-domain in functional programming?

### A co-domain is a set from which the function's output values are chosen.

7

## What are the benefits of the functional programming paradigm?

###
- Supports the decomposition and abstraction of computing problems into functions that are made up of other functions

- Is suitable for running parallel and concurrent program execution, which allows programs to run on multiprocessor systems

8

## What is a first-class object?

### An object which can appear in an expression, be assigned to a variable, be assigned as an argument and be returned in function calls.

9

## Not all combinations of functions are possible. Explain why this is.

###
A combination won't work if:

-It doesn't have the same number of inputs as outputs

-The type of the input isn't the same as the type of the output

10

## What is a higher order function?

### - A function that can take functions as arguments or/and can return a function as a result

11

## What does the map function do?

### It applies a function to all the items in a list

12

## What does the filter function do?

### Returns the elements in the domain that satisfy a given condition.

13

##
What does the fold function do?

What is the difference between foldl and foldr?

Fold is also known as reduce

###
Reduces the list to a single value by applying a given operator to the values in the list. (usually adding)

Foldl means fold left, foldr means fold right

for example: foldr (-) 100 {2,4,6,8,10) would equal -94

whereas foldl (-) 100 {2,4,6,8,10) would equal 70

14

## Name the three first class objects in functional programming.

###
Functions

Integers

Variables

15

## How many arguments can a haskell function take?

### 1, though it can look like 2 arguments are being taken, they are taken as a pair, which is treated as1 argument

16

## What is the purpose of partial function application?

### It allows the processing of multiple arguments by a function.

17

## What is meant by the head of a list in functional programming?

### The first item in the list.

18

## What is meant by the tail of a list in functional programming?

### All the items in the list apart from the first.

19

## How many data types can a list in a purely functional language contain?

### 1

20

## In functional programming languages, data structures like lists are immutable. What does this mean?

### The list cannot be changed once created.

21

## Two functions are defined as follows f x y = x + y and g x = x * x. Why is it not possible to combine these functions as f.g?

### Because f takes two arguments and g only takes one.

22

## What is a higher order function?

### A function which takes a function as an argument, returns a function as a result, or does both.

23

## What is an argument?

### The pieces of data that are passed into a function

24

## Give an example of type declaration of a function for multiplying two integers

###
MultiplyUs : : : int --> int --> int

the first two int's tell us the argument type, the last int tells us the result type

25

## Give an example of declaring a function for multiplying two integers

###
MultiplyUs x y = x * y

for example MultiplyUs 3 5 would return 15

26

## How are partial function applications implemented?

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

27

## What is functional composition?

### - The process of combining two functions to create a new function

28

## What is the benefit of functional composition?

### User's cane use the functions both separately, and in conjunction.

29

## What is required of functions that are combined?

### One function's domain (data type and number of arguments) must be the same as the other functions Co-Domain

30