GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Mindmap

Cap 4 Syntax in Functions

MENESES CHAVARRIA XUASY SANTIAGO Spanisch

Cap 4 Syntax in Functions

Inhalt der Mindmap

Cap 4 Syntax in Functions

  1. Pattern matching

    • consists of specifying patterns to which some data should conform and then checking to see if it does and deconstructing the data according to those patterns.
      • When defining functions, you can define separate function bodies for different patterns.
        • the order is important when specifying patterns and it's always best to specify the most specific ones first and then the more general ones later.
          • example
            • length' :: (Num b) => [a] -> b length' [] = 0 length' (_:xs) = 1 + length' xs
              • First we defined the result of a known input — the empty list.
              • Then in the second pattern we take the list apart by splitting it into a head and a tail.
        • we should always include a catch-all pattern so that our program doesn't crash if we get some unexpected input.
  2. Guards

    • guards are a way of testing whether some property of a value are true or false
      • A guard is basically a boolean expression.
      • the last guard is otherwise. otherwise is defined simply as otherwise = True and catches everything
      • no use = right after the function name and its parameters, before the first guard.
    • Guards are indicated by pipes that follow a function's name and its parameters.
  3. Where

    • Is a condition
      • and we put the keyword where after the guards
        • and then we define several names or functions
          • The names we define in the where section of a function are only visible to that function
        • we usualy aligned at a single column
      • where bindings can also be nested
  4. Let

    • are a syntactic construct
      • Let bindings let you bind to variables anywhere and are expressions themselves
        • it can also put let bindings inside list comprehensions
      • The form is let <bindings> in <expression>
    • are very local, so they don't span across guards
  5. Case expressions

    • blocks of code for specific values of that variable
    • we can do pattern matching
      • evaluating pieces of code based on its value

Bilder und Dateien der Mindmap

  • Cap 4 Syntax in Functions
  • Cap 4 Syntax in Functions

Informationen

Beschreibung
Mindmap am Cap 4 Syntax in Functions, erstellt von MENESES CHAVARRIA XUASY SANTIAGO am 19/02/2018.
Erstellt von
MENESES CHAVARRIA XUASY SANTIAGO · Feb 2018
Aktualisiert
7 Mär 2018
Aufrufe
0
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck