**Commands on GHCI**
❯ **ghci:** open interative terminal
❯ **:r:** recompile file
❯ **:l File.hs:** run the file, add module Module where (it able to run file without extension)
❯ **:t Value:** checks the data type

**Basic Concepts

`Types`

→** Char: `'H'`

→ [Char] or String: `"Hello World!"`

****→ Int: `1`

→ Bool: `True/False`

→ creating new data type: `data Day = Monday | Sunday`

**new type is Day and it has value constructors (Monday or Sunday)
→ Record syntax: `data Point = Point {x, y :: Double}`

→ creating new type with only one field: `newtype Data = Data Int`

**lazy evaluation

** Data Structure**
→ List:

`[1, 2, 3, 4]`

**same element type and dynamic length
→ Tuples: `(1, "Hello", 2, 'j')`

**several element type and fixed-length** Operators**
→ maths operations:

`+ - * /`

→ conditions operations: `True False not && ||`

→ equal, not equal: `== /=`

**→ sucessor: `succ 8`

→ min max: `min max [1, 2]`

→ div (integral division): `div 2 3`

→ mod (modular division): `mod 2 3`

→ odd | even (check is number is odd | even): `odd|even 2`

**`Conditional Statement`

*→ if x > 100 then x else x*2*

** Functions**
→

`nameFunction p1 p2 p3 = expression`

→ call the function: `nameFunction p1 p2 p3`

** Pattern Matching;**
→ Inspect parts of a value constructor
→

`h [] = 0`

`h (_:[]) = 1`

** _ ignore value
`h (_:x:[]) = 2 + x`

**x accepts any value**Typeclasses Highlights**
→ A typeclass is a sort of interface that defines some behavior
→ If a type is a part of a typeclass, that means that it supports and implements the behavior the typeclass describes
→ **Eq:** used for types that support equality testing, implement == and /=
→ **Show:** all types covered so far except for functions are a part of this class, it takes a value whose type is a member of Show and presents it to us as a string
→ **Read:** sort of the opposite typeclass of Show, it takes a string and returns a type which is a member of **Read**
→ **Num:** numeric typeclass, its members have the property of being able to act as numbers. It has the functions: `*abs*`

(transform negative values on positives one); * signum* (indicate if the number is positive, negative or zero);

`fromInteger`

`*fromRational*`

(convert a fraction in another type)
→ `*toRational*`

(convert the type to a Fractional)
→ `*quotRem*`

(return the quotient and the rest); `*toInteger*`

(convert the type to an Integer)
→ `*succ*`

(get the successors values) and `pred`

`*compare*`

that returns GT, LT or EQ; also `max`

`*min`

*
→ `minBound`

`maxBound`

Creating a new class: `class SimNao a where simnao :: a -> Bool`

**List Highlights**

→ to join lists: * [1, 2] ++ [3, 4] (++) [1, 2] [3, 4] or "Hello" ++ " World!"
→* to

`3 : 4 : 4 : [10, 9, 4]`

→`length [1, 2, 3]`

`head "ABCD"`

`head [1, 2]`

→`last "ABCD"`

`last [1, 2]`

`tail "ABCD"`

`tail [1, 2]`

`init "ABCD"`

`init [1, 2]`

`reverse "HASKELL"`

`reverse [1, 2, 3]`

→`take n [2, 4, 5]`

→`drop n [1, 2]`

→`[1, 2, 3] !! 2`

→`*4`

elem`[3,4,5,6]*`

`null [1, 2]`

→`sum [1, 2]`

→`product [1, 2]`

→`maximum | minimum [1, 2]`

→`x:xs`

***Ranges**
→ to produce a value range: `*[1..20]*`

→ to cycle into an infinite list: `*take 12 (cycle "LOL ")*`

→ to produce an infinite list of just one element: `*take 10 (repeat 5)*`

→ to replicate a number into a list: `*replicate 3 10*`

****List Comprehensions**
→ to build lists using expressions that will be distributed in each element
→ `[EXPRESSION(var) | var←LIST, FILTER_1, FILTER_2...FILTER_n]`

→ `doubleList xs = [2*x | x←xs]`

→ `list = [2*x+1 | x←[0 .. 10], x/=5]`

**Tuples Highlights

→ tuples are immutable, each element is fixed and each index is called a coordinate
→ get the first coordinate of a tuple: `fst ('H', "HELLO")`

→ get the second coordinate of a tuple: `snd ('H', "HELLO")`

→ produce a list of pairs: `zip [1, 2] [3,4] //[(1, 3) (2, 4)]`

**Functions Highlights**
**
→ doc the type on functions: `biggerThan :: Int → Int → Bool`

`biggerThan x y = x > y`

→ infix function: *`biggerThan x y = (>) x y`

→* **Lambda**: anonymous functions, they can be executed as values and without an explicit context `*\\p1 p2 → EXP(p1 p2)`

→* **High Order Function**: it can be passed as parameters or return another function `ev :: (Int -> Int) -> Int`

**- map:** takes a function and a list and applies that function to every element in the list, producing a new list `map (+3) [1,5,3,1,6]`

-**filter:** takes a predicate and a list and then returns the list of elements that satisfy the predicate `filter (>3) [1,5,3,2]`

-**foldr**: takes a binary function, a starting value (accumulator) and a list to fold up * foldl (\\acc x -> x : acc) []* **

**→ **Currying**: it receives multiply arguments and returns a function's sequence evaluation * sum x y z = x + y + z* **if a parameter was not passed, it returns a function with it

→ **Composition**: it's a functions chain `(funcA . funcB)`

→ **Function application ($):** the expression on its right of $ is applied as the parameter to the function on its left `sum $ map sqrt [1...5]`

→ **Guards (|):** a way of testing whether some property of a value (or several of them) are true or false `*age | age < underAge = "You're underaged" | otherwise = "You're an adult!" where underAge = 18`

*

→ **Recursion**: a way of defining functions in which the function is applied inside its own definition

→ **Polymorphic Function**: it cannot see or operate the type variables