2.7 Fundamentals of functional programming Flashcards
Define functional programming paradigm
A language where each line of code is made up of calls to a function, which in turn may be made up of other functions, or result in a value
Define declarative programming languages
Languages that specify what properties a result should have, e.g. results based on functions
Define procedural programming languages
Languages where the programmer specifies the steps that must be carried out in order to achieve a result
What are the benefits of a functional programming paradigm?
- Program requirements may be better defined as a series of abstractions based on functions
- Broader abstractions can lead to fewer errors in implementation
- Functions can be applied at any level of data abstraction making them highly reusable within a program
- Functional code is easier to test and debug
- There are no concurrency issues
- In multi-processor environments, the order functions are evaluated in is not critical
Define function type
Refers to the way in which the expression is created, for example, integer of the domain and co-domain where f: a->b is the type of function, a is the argument type and b is the output type
Define domain
A set of data of the same type which are the inputs of a function
Define co-domain
The set of values from which the outputs of a function must be drawn
Define first-class object
Any object that can be used as an argument or result of a function call
Define higher order function
A function that takes a function as its inputs or creates a function as its output
Define function application
The process of calculating the result of a function by passing it some data to produce a result
Define partial application of a function
The process of applying a function by creating an intermediate function by fixing some of the arguments to the function
Define function composition
Combining two or more functions to create more complex functions
Define map function
A function that generates an output list from an input list by applying a function to each element in the input list
Define filter function
A method of creating a subset based on specified criteria
Define reduce / fold function
A method of reducing a list to a single element by combining the elements using a function