Mindmap
Cap 3: Types and Typeclasses
Inhalt der Mindmap
Cap 3: Types and Typeclasses
The type
- Haskell has a static type system
- this is used for catch such errors at compile time instead of having your program crash
- common types
- Int and Integer
- Float is a real floating point with single precision.
- Double is a real floating point with double the precision
- Bool is a boolean type. It can have only two values: True and False.
- Haskell can infer the type
- Functions also have types
- For example
- [Char] -> [Char]
- meaning that it maps from a string to a string
- Int -> Int -> Int -> Int
- The parameters are separated with -> and there's no special distinction between the parameters and the return type
- [Char] -> [Char]
- For example
- Haskell has a static type system
Type variables
- if it's not in capital case
- it's actually a type variable
- that means that a can be of any type
- like generics in other languages
- example [a] -> a
- it takes a list of any type and returns one element of that type.
- it's actually a type variable
- if it's not in capital case
Typeclasses
- A typeclass is a sort of interface that defines some behavior
- the => symbol
- Everything before the symbol is called a class constraint
- the => symbol
- examples
- The Eq typeclass provides an interface for testing for equality.
- The functions its members implement are == and /=
- Ord The compare function takes two Ord members of the same type and returns an ordering.
- show: It takes a value whose type is a member of Show and presents it to us as a string.
- The read function takes a string and returns a type which is a member of Read.
- Enum are sequentially ordered types, they can be enumerated.
- use its types in list ranges
- can use the succ and pred functions.
- Num is a numeric typeclass
- include
- Integral
- Floating
- (Num b) => length :: [a] -> b
- include
- The Eq typeclass provides an interface for testing for equality.
- A typeclass is a sort of interface that defines some behavior
Informationen
- Beschreibung
- Mindmap am Cap 3: Types and Typeclasses, erstellt von MENESES CHAVARRIA XUASY SANTIAGO am 02/03/2018.
- Erstellt von
- MENESES CHAVARRIA XUASY SANTIAGO
- Aufrufe
- 0
- Bewertung