Docsity

Functional Programming - A level computer science, Exams of Functional Programming

Toggle sidebar
bg1
Functional Programming - A
level computer science
Benefits of functional programming: - ANS- The problem requirements may
better be defined through functional programming than by procedural
- Broader abstractions can lead to fewer errors during implementation
- Functions can be reused
- Easier to code and test as functions do not have any side effects
- No concurrency issues as no data is modified by multiple threads at once
- Good for multi-processor environment as the sequence functions are
evaluated in is not critical
Codomain - ANSThe set of values from which the outputs of a function must
be from
Declarative programming languages - ANSProgramming languages that
specify the properties of the result rather than gibing step by step
instructions
Domain - ANSA set of data of the same type which are the inputs of the
function
Filter function - ANSFilters a list based on a function returning a bool based
on its input. E.g Filter = odd: [1,2,3,4,5,6] à [1,3,5]
First class object - ANSAn object that can be used as an argument or result of
a function call. E.g. Integers or functions
pf3

Partial preview of the text

Download Functional Programming - A level computer science and more Exams Functional Programming in PDF only on Docsity!

Functional Programming - A

level computer science

Benefits of functional programming: - ANS- The problem requirements may better be defined through functional programming than by procedural

  • Broader abstractions can lead to fewer errors during implementation
  • Functions can be reused
  • Easier to code and test as functions do not have any side effects
  • No concurrency issues as no data is modified by multiple threads at once
  • Good for multi-processor environment as the sequence functions are evaluated in is not critical Codomain - ANSThe set of values from which the outputs of a function must be from Declarative programming languages - ANSProgramming languages that specify the properties of the result rather than gibing step by step instructions Domain - ANSA set of data of the same type which are the inputs of the function Filter function - ANSFilters a list based on a function returning a bool based on its input. E.g Filter = odd: [1,2,3,4,5,6] à [1,3,5] First class object - ANSAn object that can be used as an argument or result of a function call. E.g. Integers or functions

Fold function - ANSa method that reduces a list to a single element by using a function on all elements Foldl vs foldr - ANSfoldl (-) 0 [2,3,4] à ((0 - 2) - 3) - 4 = - foldr (-) 0 [2,3,4] = 2 - (3 - (4 - 0)) = 3 FoldL starts with the left most while FoldR starts with the right. Function application - ANSThe process of calculating the result of a function by passing it data to produce a result Function type - ANSRefers to the way in which a function is: input_type à output_type Functional composition - ANSCombining two or more functions together to create more complex functions Functional programming paradigm - ANSA 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 Head - ANSThe first element of a list Higher order function - ANSA function that takes another function as ain input e.g. map function can take the + function as an input, or returns a function as a result Immutability of God - ANSThe idea that in functional programming that values cannot be overwritten or changed once they are already assigned Map function - ANSThe map function applies a function to all values on a list.