Mindmap
Chapter 8
Inhalt der Mindmap
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
Informationen
- Beschreibung
- Mindmap am Chapter 8, erstellt von NICOLÁS ALBORNOZ TIBASOZA am 26/03/2019.
- Erstellt von
- NICOLÁS ALBORNOZ TIBASOZA
- Aufrufe
- 2
- Bewertung
Mehr zu Data Types and Typeclasses