Functional Programming – a Comparison
- What is a function?
A function defines a transformation, accepts data, and returns the result of the transformation.
- What is a functor?
A functor defines data, accepts a transformation, and returns the result of the transformation.
- What is a tuple?
A tuple is a container of a fixed number of miscellaneous values.
- What control flow expression was designed for use with Enums?
Pattern matching expressions are a match for Enums, and vice-versa.
- What is the name for a function with a function as a parameter?
Functions of functions are called higher-order functions.
- How many times will
fib
be called in memoizedfib(20)
?
fib
will be called 39 times. fib
will be invoked 21 times.
- What datatypes can be sent over a channel?
Sent data must implement Send
, which is usually derived by the compiler automatically.
- Why do functions need to be boxed when returned from a function?
Functions are traits so they do not have a known size at compile time. Therefore, they must either be parameterized or turned into trait objects with something like Box
.
- What does the
move
keyword do?
The move
keyword transfers ownership of variables to new contexts.
- How could two variables share ownership of a single variable?
Indirect references, such as Rc
, permit sharing references to the same data.