Mindmap
Making Our Own Types and Typeclasses
Inhalt der Mindmap
Making Our Own Types and Typeclasses
Algebraic Data Types
- Data keyword define a type
- data Bool = False | True
- Bool define a type
- False | True define a value constructors
- data Bool = False | True
- Value constructors are functions
- deriving (Show)
- Get the string representation of our value
- We can map them and partially apply them and everything
- deriving (Show)
- Export the functions and types
- Modules
- Data keyword define a type
Record Syntax
- Alternative way to write data types
- Use curly brackets
- Instance :: type
- deriving (Show)
- Constructor has several fields and it’s not obvious which field is which
- Alternative way to write data types
Type Parameters
- Take types as parameters to produce new types
- Allow us to make data types that can hold different things
- Type is polymorphic
- We use them when our data type would work regardless of the type of the value it then holds
- Never add type class constraints in data declarations.
- We end up writing more class constraints, even when we don’t need them
Derived Instances
- Haskell will see if the value constructors match
- Data contained inside matches by testing each pair of fields with ==
- The Show and Read type classes are for things that can be converted to or from strings
- Read converting strings to values of our type
- Show converting valyes of our type to strings
- Haskell will see if the value constructors match
Type Synonyms
- Give types different names so that they make more sense to someone reading our code and documentation
- Types are equivalent and interchangeable
- Word type defines a synonym for an existing type
- Can be parametryzed
- Describe what some existing type represents in our functions
- Represents something more specific in the context of our functions
- Either: Tell us about fails
- Give types different names so that they make more sense to someone reading our code and documentation
Recursive Data Structures
- Make types that have themselves as types in their fields
- One value of some type contains values of that type
- Contain more values of the same type
- Cons is another word for :
Informationen
- Beschreibung
- Ingeniería Mindmap am Making Our Own Types and Typeclasses, erstellt von Daniel Almanza am 21/03/2018.
- Erstellt von
- Daniel Almanza
- Aufrufe
- 0
- Bewertung