Mind map
Chapter 8 - Making Our Own Types and Typeclasses
Map content
Chapter 8 - Making Our Own Types and Typeclasses
We can create our own data types, it could be usefull for store diferent types of data in the same typeclass
- Syntaxis
- data <name of typeclass>
- =
- Data constructor or class definition
- Syntaxis
Record syntax
- It is used as an alternative to define data types
- data Person = Person { firstName :: String , lastName :: String , age :: Int }
Type parameters
- A value constructor can take some values parameters and then produce a new value.
- data Maybe a = Nothing | Just a
Derived instances
- This works like inheritance in programming languages, the class takes attributes from parent class.
- data Person = Person { firstName :: String , lastName :: String , age :: Int } deriving (Eq)
Type synonyms
- type String = [Char]
- Give equivalence between different types
Recursive data structures
- This data structures, allow to store the same data type into same
- data List a = Empty | Cons a (List a) deriving (Show, Read, Eq, Ord)
A yes-no typeclass
- This type of class define a data as boolean like "" or [] in javascript
- instance YesNo Int where yesno 0 = False yesno _ = True
Functor typeclass
- This class is used for map classes that can be maped like lists
- class Functor f where fmap :: (a -> b) -> f a -> f b
Information
- Description
- Mind Map on Chapter 8 - Making Our Own Types and Typeclasses, created by SANTIAGO CÁRDENAS PEDRAZA on 29/03/2020.
- Created by
- SANTIAGO CÁRDENAS PEDRAZA · Mar 2020
- Updated
- Mar 30, 2020
- Views
- 0
- Rating
More on Data Types and Typeclasses