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

Mapa mental

Making Our Own Types and Typeclasses

Samuel DELGADO MUÑOZ Espanhol

Conteúdo do mapa

Making Our Own Types and Typeclasses

  1. Algebraic data types examples

    • data Bool = False | True
    • data Int = -2147483648 | -2147483647 | ... | -1 | 0 | 1 | 2 | ... | 2147483647
  2. Create type

    • data
      • To add functionalities
        • deriving
      • simple implementation
        • data Car = Car String String Int deriving (Show)
      • best implementation
        • data Car = Car {company :: String, model :: String, year :: Int} deriving (Show)
      • multiple defining
        • |
  3. type parameters

    • constructors
      • data Maybe a = Nothing | Just a
        • rename parameters into functions
          • tellCar :: Car -> String tellCar (Car {company = c, model = m, year = y}) = "This " ++ c ++ " " ++ m ++ " was made in " ++ show y
    • derived instances
      • deriving (Eq)
        • compare types
      • add functionality of class
      • deriving (Eq, Show, Read)
  4. Type synonyms

    • type String = [Char]
    • types are equivalent and interchangeable
    • type AssocList k v = [(k,v)]
  5. Recursive data structures

    • value of some type contains values of that type
      • 3:(4:(5:6:[]))
    • data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show, Read, Eq)
      • a -> Tree a - > Tree a
  6. Typeclasses 102

    • interfaces
      • equality
      • comparing
      • ordering
      • enumeration
    • class Eq a where
    • instance Eq TrafficLight where
    • class (Eq a) => Num a where
  7. Functor typeclass

    • mapping
      • read class
    • (==) :: (Eq a) => a -> a -> Bool
    • map :: (a -> b) -> [a] -> [b]
  8. Kinds and some type-foo

    • Family type
      • :k <type>
        • :k Int
          • Int :: *
    • data Barry t k p = Barry { yabba :: p, dabba :: t k }
      • Barry :: (* -> *) -> * -> * -> *

Informações

Descrição
Mapa Mental sobre Making Our Own Types and Typeclasses, criado por Samuel DELGADO MUÑOZ em 23-09-2018.
Visualizações
0
Avaliação

Mais sobre Data Types and Typeclasses

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?