Mapa mental
Higher order functions
Contenido del mapa
Higher order functions
Curried functions
- functions that accepted several parameters
- space = operator
- has the highest precedence
- space = operator
- max 4 5 = (max 4) 5
- -> (a -> a)
- a function that takes an a and returns an a
- functions that accepted several parameters
Functions that:
- take functions as parameters
- applyTwice :: (a -> a) -> a -> a applyTwice f x = f (f x)
- the first parameter is a function that takes something and returns that same thing
- map
- takes
- function
- &&
- List
- map :: (a -> b) -> [a] -> [b]
- List
- &&
- function
- applies the function to every element in the list
- producing a new list.
- map _ [] = []
- map f (x:xs) = f x : map f xs
- takes
- filter
- takes
- predicate
- &&
- List
- filter :: (a -> Bool) -> [a] -> [a]
- &&
- predicate
- returns the list of elements that satisfy the predicate
- filter _ [] = []
- filter p (x:xs)
- | p x = x : filter p xs
- | otherwise = filter p xs
- | p x = x : filter p xs
- filter p (x:xs)
- filter _ [] = []
- takes
- applyTwice :: (a -> a) -> a -> a applyTwice f x = f (f x)
- return functions as return values
- take functions as parameters
Lambdas
- anonymous functions
- expressions too
- need a function only once?
- \
- anonymous functions
Folders
- reduce the list to some single value.
- takes
- binary function
- takes 2 parameters
- starting value
- list
- binary function
- takes
- fold1
- folds the list up from the left side
- foldr
- folds the list up from the right side
- reduce the list to some single value.
function application
- $
- lowest precedence
- right-associative.
Function composition
- (f o g) (x)
- (f (g(x))
- two functions produces a new function
- when called with a parameter,
- is like calling g with the parameter and then calling the f with that result.
- when called with a parameter,
- .
- (f o g) (x)
Información
- Descripción
- Informática Mapa Mental sobre Higher order functions, creado por Diego Alvarez el 04/03/2018.
- Creado por
- Diego Alvarez
- Visitas
- 0
- Valoración