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

Mapa mental

Our Own Types and Typeclasses

MENESES CHAVARRIA XUASY SANTIAGO Espanhol

Conteúdo do mapa

Our Own Types and Typeclasses

  1. Algebraic data types

    • data means that we're defining a new data type. The part before the = denotes the type
      • To make our own type to represent a shape
        • a shape can be a circle or a rectangle
          • data Shape = Circle Float Float Float | Rectangle Float Float Float Float
      • if we add deriving (Show) at the end of a data declaration, Haskell automagically makes that type part of the Show typeclass
      • If we wanted to export the functions and types that we defined here in a module
        • module Shapes ( Point(..) , Shape(..) , surface , nudge , baseCircle , baseRect ) where
  2. Record syntax

    • Here's how we could achieve a functionality with record syntax
      • data Person = Person { firstName :: String , lastName :: String , age :: Int , height :: Float , phoneNumber :: String , flavor :: String } deriving (Show)
      • we use curly brackets
      • First we write the name of the field, for instance
      • firstName and then we write a double colon ::
  3. Type parameters

    • A value constructor can take some values parameters and then produce a new value
      • data Maybe a = Nothing | Just a
    • 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

    • a typeclass is a sort of an interface that defines some behavior.
      • A type can be made an instance of a typeclass if it supports that behavior
      • Haskell can derive the behavior of our types in these contexts if we use the deriving keyword when making our data type.
    • we first make our data type and then we think about what it can act like.
  5. Type synonyms

    • they're just about giving some types different names so that they make more sense to someone reading our code and documentation
      • Type synonyms can also be parameterized
        • If we want a type that represents an association list type
          • type AssocList k v = [(k,v)]

Informações

Descrição
Mapa Mental sobre Our Own Types and Typeclasses, criado por MENESES CHAVARRIA XUASY SANTIAGO em 13-04-2018.
Visualizações
1
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?