¡GoConqr estrena diseño! Cuéntanos qué te parece.

Mapa mental

Making Our Own Types and Typeclasses

Samuel DELGADO MUÑOZ Español

Contenido del 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 :: (* -> *) -> * -> * -> *

Información

Descripción
Mapa Mental sobre Making Our Own Types and Typeclasses, creado por Samuel DELGADO MUÑOZ el 23/09/2018.
Visitas
0
Valoración

Más sobre Data Types and Typeclasses

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?