GoConqr has a new look! Let us know what you think.

Mind map

Making Our Own Types and Typeclasses

Samuel DELGADO MUÑOZ Spanish

Map content

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

Information

Description
Mind Map on Making Our Own Types and Typeclasses, created by Samuel DELGADO MUÑOZ on 23/09/2018.
Views
0
Rating

More on Data Types and Typeclasses

Feedback

What is it about?

What do you think of the new look?

How do you like it?