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

Mapa mental

Making our own types and typeclass

JUAN PABLO VALENCIA QUINTERO Espanhol

Conteúdo do mapa

Making our own types and typeclass

  1. Algebraic data types intro

    • one way is to use the data keyword to define a type
      • data means that we're defining a new data type
        • Value constructors are actually functions that ultimately return a value of a data type. Let's take a look at the type signatures for these two value constructors.
        • Value constructors are functions, so we can map them and partially apply them and everything
  2. Record syntax

    • Use record syntax when a constructor has several fields and it's not obvious which field is which
  3. Type parameters

    • A value constructor can take some values parameters and then produce a new value
    • type constructors can take types as parameters to produce new types. This might sound a bit too meta at first, but it's not that complicated
    • Type parameters are useful because we can make different types with them depending on what kind of types we want contained in our data type.
  4. Derived instances

    • The Show and Read typeclasses are for things that can be converted to or from strings, respectively
    • Read is pretty much the inverse typeclass of Show. Show is for converting values of our a type to a string, Read is for converting strings to values of our type
  5. Type synonyms

    • los constructores de tipos pueden tomar tipos como parámetros para generar nuevos tipos
    • When we were dealing with the Data.Map module, we first represented a phonebook with an association list before converting it into a map
  6. Recursive data structures

    • As we've seen, a constructor in an algebraic data type can have several
    • we can create recursive data types, where one value of some type contains values of that type
    • cons is another word for :. You see, in lists, : is actually a constructor that takes a value and another list and returns a list
  7. Typeclasses 102

    • typeclasses are like interfaces
    • A typeclass defines some behavior (like comparing for equality, comparing for ordering, enumeration) and then types that can behave in that way are made instances of that typeclass. The behavior of typeclasses is achieved by defining functions or just type declarations that we then implement
  8. A yes-no typeclass

    • Even though strictly using Bool for boolean semantics works better in Haskell, let's try and implement that JavaScript-ish behavior anywa
    • The YesNo typeclass defines one function
  9. The Functor typeclass

    • We see that it defines one function, fmap, and doesn't provide any default implementation for it
    • The type of fmap is interesting. In the definitions of typeclasses so far, the type variable that played the role of the type in the typeclass was a concrete type
  10. Kinds and some type-foo

    • Type constructors take other types as parameters to eventually produce concrete types

Informações

Descrição
Mapa Mental sobre Making our own types and typeclass, criado por JUAN PABLO VALENCIA QUINTERO em 04-04-2020.
Visualizações
1
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?