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

Mind map

Chapter 8 - Creating Our Own Types and Classes of Types

CAMILO ENRIQUE FONSECA PATIÑO Spanish

Map content

Chapter 8 - Creating Our Own Types and Classes of Types

  1. To create our own data types you can use the word data. data means that we are going to define a new data type. .

    • data(type of date) =data constructors.
      • =
        • The part to the right are the data constructors
        • The part to the left of the = denotes the type.
  2. record syntax

    • It is used as an alternative to define data types.
    • e.g.
      • data Person = Person { firstName :: String , lastName :: String}
  3. type parameters

    • Type parameters are useful because they allow us to create different types depending on the type we want to store in our data types.
    • e.g
      • data Maybe a = Nothing | Just a
  4. derived instances

    • Deriving an instance consists of placing the word deriving ( class ) at the end of the declaration of the types of data that the constructor will contain.
    • e.g
      • data Person = Person { ...} deriving (Eq, Show, Read)
  5. Type synonyms

    • simply give some type a different name.
    • e.g
      • type PhoneBook = [(String,String)]
      • type PhoneNumber = String
      • type Name = String
      • type PhoneBook = [(Name,PhoneNumber)]
  6. Recursive data structures

    • we can create types whose builder fields are the type itself. In this way, we can create recursive data structures, in which a value of a certain type contains values of that same type, which will continue to contain values of the same type and so on.
    • e.g
      • data List a = Empty | Cons a (List a)
  7. Yes/No type class

    • This function takes a value from any type that can express some value of truth and tells us if it is true or not.
    • ghci> yesno $ length [] False
  8. Functor type class

    • the Functor type class, which is basically for things that can be mapped. It only works with lists.

Information

Description
Mind Map on Chapter 8 - Creating Our Own Types and Classes of Types, created by CAMILO ENRIQUE FONSECA PATIÑO on 31/03/2019.
Views
5
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?