GoConqr has a new look! Let us know what you think.

Mind map

Higher order functions

MENESES CHAVARRIA XUASY SANTIAGO Spanish

Map content

Higher order functions

  1. caracteristics

    • :: (a -> a) -> a -> a
      • Before, we didn't need parentheses because -> is naturally right-associative.
        • buy here they're mandatory
      • ndicate that the first parameter is a function that takes something and returns that same thing
      • The second parameter is something of that type also and the return value is also of the same type
    • In the body
      • applyTwice f x = f (f x) rocktopus
        • 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
  2. Haskell functions can take functions as parameters and return functions as return values

    • If the function requires us to pass it a function that takes only one paramete
      • we can just partially apply a function to the point where it takes only one parameter and then pass it.
  3. a single higher order function can be used in very versatile ways.

    • Imperative programming usually uses stuff like for loops, while loops, setting something to a variable, checking its state
  4. Maps and filters

    • map takes a function and a list and applies that function to every element in the list
      • producing a new list
        • map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs
    • is similar with a list comprehension
      • but using map is much more readable
    • filter is a function that takes a predicate
      • that is a function that tells whether something is true or not
        • and return a list and then returns the list of elements that satisfy the predicate
          • ilter :: (a -> Bool) -> [a] -> [a] filter _ [] = [] filter p (x:xs) | p x = x : filter p xs | otherwise = filter p xs
  5. Lambdas

    • are anonymous functions that are used because we need some functions only once
      • the purpose is passing it to a higher-order function
    • To make a lambda, we write a \
      • then we write the parameters, separated by spaces
        • After put a -> and then the function body.

Information

Description
Mind Map on Higher order functions, created by MENESES CHAVARRIA XUASY SANTIAGO on 04/03/2018.
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?