Answer
Flashcards · 9645 · A Level Topic 12
Functional programming (A Level) flashcards
9 cards on A Level Topic 12. Pick a subtopic or study them all.
Study mode needs JavaScript. Every card is listed below, so you can still cover the answers and test yourself.
Choose your cards
Session complete
Worth another look:
All 9 cards
For a quick read-through or printing. Cover the right-hand side to test yourself.
Topic 12: Functional programming
- What do f: A → B, the domain and the co-domain mean?
- f takes arguments of type A and returns results of type B. The domain (A) is the set inputs come from; the co-domain (B) is the set outputs come from, though not every member has to be output.
- What is a first-class object?
- A value that may appear in expressions, be assigned to a variable, be passed as an argument and be returned from a function call. In functional languages, functions are first-class objects.
- What is function composition g ∘ f?
- It combines f: A → B and g: B → C into one function of type A → C, with f applied first. The co-domain of f must match the domain of g.
- What is a higher-order function?
- A function that takes a function as an argument, returns a function, or both, e.g. map, filter and fold.
- What do map, filter and fold do?
- map applies a function to every element of a list. filter keeps the elements for which a condition is true. fold (foldl or foldr) combines the elements into one value, starting from a given value.
- What do head, tail and null return for the list [5, 2]?
- head gives 5 (the first element). tail gives [2] (the rest, always a list). null gives False (the list is not empty).
- How does Haskell choose which equation of a function to use?
- By pattern matching: it tries the equations from top to bottom and uses the first pattern that fits, such as 0, [], a name, (x:xs) for any non-empty list or [x] for a one-item list.
- How is a function applied in Haskell, and how is whole-number division written?
- Arguments follow the name with spaces and no brackets or commas, e.g. name 7 2. div and mod are written between back-quotes: 17 div 5 = 3 and 17 mod 5 = 2.
- Name the number sets ℕ, ℤ, ℚ and ℝ
- ℕ: natural numbers 0, 1, 2, ... (zero included). ℤ: integers. ℚ: rational numbers p/q with integers p and q. ℝ: real numbers, including π and √2.