Mindmap
Introduce el texto aquí
Inhalt der Mindmap
Introduce el texto aquí
INTRODUCTION TO THE TYPES OF ALGERATIC DATA.
- Data -> to define a type
- data Shape = Circle Float Float Float | Rectangle Float Float Float Float deriving (Show)
- Data -> to define a type
Registration syntax
- data Person = Person { firstName :: String , lastName :: String , age :: Int , height :: Float , phoneNumber :: String , flavor :: String } deriving (Show)
Parameters of type
- A data constructor can take some values as parameters and produce a new value.
- data Maybe a = Nothing | Just a
- A data constructor can take some values as parameters and produce a new value.
Derivative instances
- a class of types is a kind of interface that defines a behavior.
- Haskell can derive the behavior of our types
- Using the word Deriving when we defined it, we would achieve this
- data Person = Person { firstName :: String , lastName :: String , age :: Int } data Person = Person { firstName :: String , lastName :: String , age :: Int } deriving (Eq)
- By deriving the show class, the person can be shown on the screen because this method converts the data type to a string
- With the Read function the reverse process could be done.
- Using the word Deriving when we defined it, we would achieve this
- • Eq, Ord, Enum, Bounded, Show y Read
- The Enum class are for things that have a predecessor and successor
Synonyms of type
- The synonyms of type do not do anything by themselves, they just give some kind a different name, so that it gets some meaning for someone who is reading our code or documentation.
- type String = [Char]
- Give a synonym to the String type is something that is usually when they want to convey some more information about the purpose of the chains in their functions and what they represent.
- When we are interested in how or why something has failed, we usually use the type Either a b as a result, where a is some kind of type that can tell us something about a possible failure, and b is the type of a satisfactory calculation
- The synonyms of type do not do anything by themselves, they just give some kind a different name, so that it gets some meaning for someone who is reading our code or documentation.
Recursive data structures
- We can define functions that are automatically infixed if we name them only with special characters.
- infixr 5 :-: data List a = Empty | a :-: (List a) deriving (Show, Read, Eq, Ord)
- We can define functions that are automatically infixed if we name them only with special characters.
Type classes step by step (2nd part)
- When we say that a type is an instance of a type class, we are saying that we can use the functions of that type class with that type.
- The type class Yes-No
- instance YesNo Int where yesno 0 = False yesno _ = True
The kind of functor types
- The Functor type class is basically for things that can be mapped.
- The list type is a member of the Functor type class.
- F would be a type constructor and not a type
- class Functor f where fmap :: (a -> b) -> f a -> f b
Informationen
- Beschreibung
- Mindmap am Introduce el texto aquí, erstellt von CASTILLO ZAMBRANO LUIS FELIPE am 19/03/2018.
- Erstellt von
- CASTILLO ZAMBRANO LUIS FELIPE
- Aufrufe
- 2
- Bewertung