Mapa mental
Making Our Own Types and Typeclasses
Contenido del mapa
Making Our Own Types and Typeclasses
Algebraic data types
- use the data keyword to define a type
- means that we're defining a new data type.
- has to have constructor attributes
- some data types Bool, Int, Char, Maybe
- Representation of a shape in haskell
- tuples
- could also represent a 3D vector or anything else
- make our own type to represent a shape
- can optionally add some types after it and those types define the values it will contain
- can also export data types in diferent modules
- use the data keyword to define a type
Record syntax
- define what information wan to record
- set the data type
- use curly brackets
- write a double colon
- specify the type
- creates functions that lookup fields in the data type
- specify the type
- write a double colon
- define what information wan to record
Type parameters
- can take some values parameters and then produce a new value
- can take types as parameters to produce new types
- can make different types with them depending on what kind of types we want contained in our data type
Derived instances
- Haskell can automatically make our type an instance of any of the following typeclasses
- Haskell can derive the behavior of the types
Type synonyms
- they do nothing by itself
- gave some types different names so that they make more sense to someone reading our code and documentation
Información
- Descripción
- Mapa Mental sobre Making Our Own Types and Typeclasses, creado por HERRERA BOHORQUEZ JAVIER FELIPE el 09/10/2020.
- Creado por
- HERRERA BOHORQUEZ JAVIER FELIPE
- Visitas
- 0
- Valoración
Más sobre Data Types and Typeclasses