Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
4 Cards in this Set
- Front
- Back
First-class Function |
functions can be computed, passed, stored, etc. wherever other values can be computed, passed, stored, etc. As examples, we can pass them to functions, return them from functions, put them in pairs, have them be part of the data a datatype constructor carries, etc |
|
Higher-order Function |
a function that takes or returns other functions |
|
Generic Types |
It lets functions take arguments of any type. It is a separate issue from first-class functions:
There are functions that take functions and do not have polymorphic types There are functions with polymorphic types that do not take functions.
However, many of our examples with first-class functions will have polymorphic types. That is a good thing because it makes our code more reusable.
Without parametric polymorphism, we would have to redefine lists for every type of element that a list might have. Instead, we can have functions that work for any kind of list, like length, which has type ’a list -> int even though it does not use any function arguments. Conversely, here is a higher-order function that is not polymorphic: it has type (int->int) * int -> int |
|
Anonymous Funciton |
It is a function that takes an argument y and has body 3*y. The fn is a keyword and => (not =) is also part of the syntax. We never gave the function a name (it is anonymous, see?), which is convenient because we did not need one. We just wanted to pass a function to n_times, and in the body of n_times, this function is bound tof |