GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Mindmap

Making Our Own Types and Typeclasses

Daniel Almanza Ingeniería Spanisch

Inhalt der Mindmap

Making Our Own Types and Typeclasses

  1. Algebraic Data Types

    • Data keyword define a type
      • data Bool = False | True
        • Bool define a type
        • False | True define a value constructors
    • Value constructors are functions
      • deriving (Show)
        • Get the string representation of our value
      • We can map them and partially apply them and everything
    • Export the functions and types
      • Modules
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck