Mind map
Chapter 8 - Creating Our Own Types and Classes of Types
Map content
Chapter 8 - Creating Our Own Types and Classes of Types
To create our own data types you can use the word data. data means that we are going to define a new data type. .
- data(type of date) =data constructors.
- =
- The part to the right are the data constructors
- The part to the left of the = denotes the type.
- =
- data(type of date) =data constructors.
record syntax
- It is used as an alternative to define data types.
- e.g.
- data Person = Person { firstName :: String , lastName :: String}
type parameters
- Type parameters are useful because they allow us to create different types depending on the type we want to store in our data types.
- e.g
- data Maybe a = Nothing | Just a
derived instances
- Deriving an instance consists of placing the word deriving ( class ) at the end of the declaration of the types of data that the constructor will contain.
- e.g
- data Person = Person { ...} deriving (Eq, Show, Read)
Type synonyms
- simply give some type a different name.
- e.g
- type PhoneBook = [(String,String)]
- type PhoneNumber = String
- type Name = String
- type PhoneBook = [(Name,PhoneNumber)]
Recursive data structures
- we can create types whose builder fields are the type itself. In this way, we can create recursive data structures, in which a value of a certain type contains values of that same type, which will continue to contain values of the same type and so on.
- e.g
- data List a = Empty | Cons a (List a)
Yes/No type class
- This function takes a value from any type that can express some value of truth and tells us if it is true or not.
- ghci> yesno $ length [] False
Functor type class
- the Functor type class, which is basically for things that can be mapped. It only works with lists.
Information
- Description
- Mind Map on Chapter 8 - Creating Our Own Types and Classes of Types, created by CAMILO ENRIQUE FONSECA PATIÑO on 31/03/2019.
- Created by
- CAMILO ENRIQUE FONSECA PATIÑO
- Views
- 5
- Rating