O GoConqr está de visual novo! Conte para nós o que você achou.

Mapa mental

Making Our Own Types and Typeclasses

Daniel Almanza Ingeniería Espanhol

Conteúdo do mapa

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 :

Informações

Descrição
Ingeniería Mapa Mental sobre Making Our Own Types and Typeclasses, criado por Daniel Almanza em 21-03-2018.
Criado por
Daniel Almanza
Visualizações
0
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?