Section 12 - Functional programming Flashcards
What is a programming paradigm?
A style of computer programming
What are the 4 types of programming paradigms?
- Procedural programming
- Object-orientated programming
- Declarative programming
- Functional programming
What is procedural programming?
Where a series of instructions tells the computer what to do with the input in order to solve the problem
What is structured programming?
A form of procedural programming which uses the modular techniques to split large programs into manageable chunks
What programming constructs does structured programming use?
- Sequence
- Selection
- Iteration
- Recursion
What is object-orientated programming?
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
What is declarative programming?
Where you write statements the describe the problem to be solved, with the language implementation deciding the best way to solve it
What is functional programming?
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
What is a function?
A mapping from the domain to the co-domain
What is the domain?
The set of inputs
What is the co-domain?
The set of possible outputs
What is always true about the domain and co-domain?
They are always subsets of objects in some data type
What is Haskell?
A functional programming language
What is a parameter in Haskell?
A reference declared in a function declaration
What is an argument in Haskell?
A value or expression passed to a function
What is function application?
The process of giving particular inputs to a function
What are first-class objects?
An object that can:
- Appear in expressions
- Be assigned to a variable
- Be assigned as an argument
- Be returned in a function call
What is unique about variables in functional programming?
The value of a variable is immutable and the program is stateless
What is referential transparency?
A function that is called twice with the same parameters will always return the same result
What is the advantage of referential transparency?
It is relatively easy to write correct, bug free programs
What does it mean to have no side effects?
The only thing a function can do is calculate something and return a result so it has no side effects
What is functional composition?
Combining 2 functions to get a new function, by using a function as an argument
What are types?
Sets of values
What are typeclasses?
Sets of types