GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Mindmap

Making Our Own Types and Typeclasses

Samuel DELGADO MUÑOZ Spanisch

Inhalt der Mindmap

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

Informationen

Beschreibung
Mindmap am Making Our Own Types and Typeclasses, erstellt von Samuel DELGADO MUÑOZ am 23/09/2018.
Aufrufe
0
Bewertung

Mehr zu Data Types and Typeclasses

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck