Haskell Types

  • Primitive: Int, Bool, Float, Char, Integer
  • Constructed: Lists: [a], String = [Char], Tuples: (a, b, c)
  • Algebraic Data Type: (more constructed)
  • 
                data Apple = Gala | Honeycrisp | Jazz -- Enum
                data Apple = Ap Color String Int      -- Cartesian: 
                          -- Ap is the constructor, the * are invisible
                data Tree = A  Apple | B Orange       -- Union
                data Node = Y Int Node | N Int        -- recursive
                
  • Can add functions to Algebraic Data Types
  • 
                data Foo = F Int Char [Int]
                  deriving Show        -- for printing
                data Bar = B Int Int
                  deriving (Show, Eq)  -- for printing AND supporting == and !=
                data Tree = Gala | H Tree | Ap Color String Int 
                                 | B Orange | Z Node         -- some crazy type