Functional Programming Fundamentals Flashcards

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

Functional programming

A

A function is a self contained statement that returns a value when given all required inputs and executed

They are the building blocks of a program in functional programming

Given the same input the function will always return the same output without altering any other data - to achieve this data in functional programs is immutable; if results need to be stored, then new data structures need to be made rather than updating previously used variables

Functional programs need to be stateless, meaning they dont remember anything that has happened before

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

Functions

A

A function is a rule that, for each element in some set A of inputs, assigns an output chosen from set B without using every member of set B

The set from which inputs are chosen is the domain; the set from which outputs are calculated is the co-domain
eg. F(x) = X^2, where x is the domain and x^2 is the co-domain

All functions have a function type defined as
- F: A → B, where F is the function, A is the argument type and input and B is the result type and output of the function

The domain and co-domain are always subsets of objects in some data type

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

First class objects

A

A first class object is an object which may:
- Appear in an expression
- Be assgines to a variable
- Be assigned as arguments to a function
- Be returned by a function call

Functions are also first class objects in functional programming languages

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

Function application

A

Giving particular inputs to a function is called function application

eg. Square 3, where Square: integer → integer, would be an application of the argument 3 to the Square function

Partial function application is where it is possible to call a function with fewer arguments than needed - some of the arguments are fixed and can be stored as a variable for later use
This is possible because functions are first class objects

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

Function Composition

A

Functional composition is the act of combining two functions to create a new function.

The benefit of this is that the user is able to use the functions both separately, and in
conjunction.

Any two functions can be combined as long as 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