Mapa mental
Chapter 8
Contenido del mapa
Chapter 8
Algebraic data types
- Define our own data types
- using the word "data"
- means that a new data type is being defined
- It is necessary to write the data type name
- Value constructors
- Defines the values that can take the data type that is going to be defined
- Example
- data Bool = True | False
Record syntax
- Modules can define data types aswell
- To be more simple to understand and read it is used record syntax
- Works the same way as the algebraic data types, the only difference is that it's more readable
- Record syntax works like object oriented prgramming
- We define the attributes and their data types
- To be more simple to understand and read it is used record syntax
- Modules can define data types aswell
Type parameters
- Instead of having values as parameters we have data types as parameters
- For example
- data Maybe a = Nothing | Just a
- "a" is a type parameter
- the result could be Just Int or Just Char
- "a" is a type parameter
- data Maybe a = Nothing | Just a
Derived instances
- It is used to implement a behaviour in a new data type
- To do so it is necessary to use the word "Deriving"
- And then write the typeclass we want to implement
- For example: deriving (Eq, Show, Read)
- To do so it is necessary to use the word "Deriving"
- It is used to implement a behaviour in a new data type
Type synonims
- Give types a different name
- For example [Char], its type synomim would be String
- Give types a different name
Typeclasses 102
- As we can define modules, we can also define our own typeclasses
- To define a new typeclass we use the word "class" followed by the name and then "where"
- class Eq a where
- To define a new typeclass we use the word "class" followed by the name and then "where"
- As we can define modules, we can also define our own typeclasses
Información
- Descripción
- Mapa Mental sobre Chapter 8, creado por NICOLÁS ALBORNOZ TIBASOZA el 26/03/2019.
- Creado por
- NICOLÁS ALBORNOZ TIBASOZA
- Visitas
- 2
- Valoración
Más sobre Data Types and Typeclasses