¡GoConqr estrena diseño! Cuéntanos qué te parece.

Mapa mental

Syntax in Functions

carlos marin Español

Contenido del mapa

Syntax in Functions

  1. functions

    • Head Function
      • head' :: [a] -> a head' [] = error "¡Hey, no puedes utilizar head con una lista vacía!" head' (x:_) = x
    • length
      • length' :: (Num b) => [a] -> b length' [] = 0 length' (_:xs) = 1 + length' xs
    • sum
  2. data type

    • numbers, characters, lists, tuples, etc.
      • lucky :: (Integral a) => a -> String lucky 7 = "LUCKY NUMBER SEVEN!" lucky x = "Sorry, you're out of luck, pal!"
        • patterns
          • will be checked from top to bottom and when it conforms to a pattern, the corresponding function body will be used.
          • Normally we use as patterns to avoid repeating ourselves when matching against a bigger pattern when we have to use the whole thing again in the function body.
  3. factorial function recursively

    • Recursion is important in Haskell and we'll take a closer look at it later.
      • factorial :: (Integral a) => a -> a factorial 0 = 1 factorial n = n * factorial (n - 1)
  4. Pattenrs

    • Pattern matching can also fail. If we define a function like this:
      • charName :: Char -> String charName 'a' = "Albert" charName 'b' = "Broseph" charName 'c' = "Cecil"
        • Non-exhaustive patterns in function charName
      • When making patterns, we should always include a catch-all pattern so that our program doesn't crash if we get some unexpected input.
    • Pattern matching can also be used on tuples.
    • The x:xs pattern
      • is used a lot, especially with recursive functions. But patterns that have : in them only match against lists of length 1 or more.
  5. Pairs

    • fst and snd extract the components
  6. List

    • can be used in pattern matching.
      • You can match with the empty list [] or any pattern that involves : and the empty list
  7. imperative languages

    • if else
    • where
    • let
      • The names that you define in the let part are accessible to the expression after the in part
    • Case expressions
      • expression is matched against the patterns.

Información

Descripción
Mapa Mental sobre Syntax in Functions, creado por carlos marin el 27/02/2018.
Creado por
carlos marin
Visitas
0
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?