2018-11-14 13:10

Page 1
- Haskell is a
*strongly typed*language.- All values have a type. All type errors are reported, you can't escape the type system.

- Haskell is a
*statically typed*language.- Types are checked at compile-time (before the program is run).

- Haskell supports
*type inference*and*polymorphism*.- If you omit the type, Haskell infers a type automatically.
- Most of the time it doesn't need to guess, there is one type that is the best type.

- :
**Bool**,**False**.**True** - ,
**Int**:**Integer**,`0`

,`1`

,`-`5`42`

- ,
**Float**:**Double**,`0.0`

,`3.14`

,`1.5e9`

`-`1.0 - :
**Char**,`'A'`

,`'B'`

,`'x'`

,`'/'`

.`'\n'`

- :
**String**,`""`

,`"Haskell"`

`"Hello world!\n"`

t1=(False, 42)::(Bool,Int)t2=("Hello",False,5)::(String,Bool,Int)t3=("Haskell",True,4,0.5)::(String,Bool,Int,Double)t0=()::() -- the empty tuple

l1=[2,3,5,7,11]::[Integer]l2=["Hello","world"]::[String]l3=[]::[Bool]l4=[]::[Int] -- the empty list has many types

- Maybe
**data****Maybe**`a`**=****Nothing****|****Just**`a``m1`**=****Nothing****::****Maybe**`a``m2`**=****Just**"Hello"**::****Maybe****String**

- Either
**data****Either**`a``b`**=****Left**`a`**|****Right**`b``e1`**=****Left**"Hello"**::****Either****String**`b``e2`**=****Right**42**::****Either**`a`**Int**`e3`**=**[**Right**42,**Left**"Hello"]**::**[**Either****String****Int**]

power::Integer->Integer->IntegerexampleFunction::(Bool,Int,String)->Booldoubles::[Integer]->[Integer]summary::[String]->String

[[

**Double**]][(

**Int**,**String**)]([

**Int**],[**String**])[(

**Int**,[**String**])]- Function types too!
[(

**Int****->****String**,[**Int**])]**->****String**[(

`a`**->**`b`,`a`)]**->**[`b`]

`length`**::**[`a`]**->****Int**(`++`)**::**[`a`]**->**[`a`]**->**[`a`]`fst`**::**(`a`,`b`)**->**`a``map`**::**(`a`**->**`b`)**->**[`a`]**->**[`b`]`filter`**::**(`a`**->****Bool**)**->**[`a`]**->**[`a`]- The same implementation works for all types. Parametricity.

`show`**::****Show**`a`**=>**`a`**->****String**(`+`),(`*`)**::****Num**`a`**=>**`a`**->**`a`**->**`a`(`==`)**::****Eq**`a`**=>**`a`**->**`a`**->****Bool**(`<`), (`<=`)**::****Ord**`a`**=>**`a`**->**`a`**->****Bool**- Name reuse. Different implementations are needed for different types.