Mind map
Cap 4 Syntax in Functions

Map content
Cap 4 Syntax in Functions
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.
- length' :: (Num b) => [a] -> b length' [] = 0 length' (_:xs) = 1 + length' xs
- example
- we should always include a catch-all pattern so that our program doesn't crash if we get some unexpected input.
- 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.
- When defining functions, you can define separate function bodies for different patterns.
- 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.
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.
- guards are a way of testing whether some property of a value are true or false
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
- and then we define several names or functions
- where bindings can also be nested
- and we put the keyword where after the guards
- Is a condition
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>
- Let bindings let you bind to variables anywhere and are expressions themselves
- are very local, so they don't span across guards
- are a syntactic construct
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
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
