Mapa mental
Higher order functions
Conteúdo do mapa
Higher order functions
Haskell functions can take functions as parameters and return functions as return values
Curried functions
- Putting a space between two things is simply function application.
partially applied function
- that takes as many parameters as we left out
Infix functions
- To section an infix function, simply surround it with parentheses and only supply a parameter on one side
- That creates a function that takes one parameter and then applies it to the side that's missing an operand
- To section an infix function, simply surround it with parentheses and only supply a parameter on one side
Functions can take functions as parameters and also return functions.
- applyTwice :: (a -> a) -> a -> a applyTwice f x = f (f x)
- They indicate that the first parameter is a function that takes something and returns that same thing.
- applyTwice :: (a -> a) -> a -> a applyTwice f x = f (f x)
The body of the function is pretty simple. We just use the parameter f as a function, applying x to it by separating them with a space and then applying the result to f again.
zipWith
- takes a function and two lists as parameters and then joins the two lists by applying the function between corresponding elements
Functional programming
- uses higher order functions to abstract away common patterns, like examining two lists in pairs and doing something with those pairs or getting a set of solutions and eliminating the ones you don't need.
flip
- takes a function and returns a function that is like our original function, only the first two arguments are flipped.
Maps and filters
- map
- takes a function and a list and applies that function to every element in the list, producing a new list.
- chain function
- numLongChains :: Int
- because length returns an Int instead of a Num a
- numLongChains :: Int
- filter
- takes a predicate (a predicate is a function that tells whether something is true or not, so in our case, a function that returns a boolean value) and a list and then returns the list of elements that satisfy the predicate.
- && function.
- map
Lambdas \
- anonymous functions that are used because we need some functions only once
- we make a lambda with the sole purpose of passing it to a higher-order function.
- lambdas can take any number of parameters:
- we make a lambda with the sole purpose of passing it to a higher-order function.
- anonymous functions that are used because we need some functions only once
Only folds and horses
- A fold takes a binary function, a starting value (I like to call it the accumulator) and a list to fold up.
Informações
- Descrição
- Mapa Mental sobre Higher order functions, criado por carlos marin em 27-02-2018.
- Criado por
- carlos marin
- Visualizações
- 0
- Avaliação