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

Mind map

Cap 4 Syntax in Functions

MENESES CHAVARRIA XUASY SANTIAGO Spanish

Cap 4 Syntax in Functions

Map content

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

Images and files in the map

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

Information

Description
Mind Map on Cap 4 Syntax in Functions, created by MENESES CHAVARRIA XUASY SANTIAGO on 19/02/2018.
Created by
MENESES CHAVARRIA XUASY SANTIAGO · Feb 2018
Updated
Mar 7, 2018
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?