- allows us to add structure to the values in our programs
- defining our own types also imrpoves the safety of our code
- haskell will not allow us to accidentally mix values of two values that are structurally similar but have different names.
-- file: ch03/BookStore.hs
data BookInfo = Book Int String [String]
deriving (Show)
- The BookInfo after the
data
keyword is the name of our new type. We call
BookInfo a type constructor.
- The
Book
that follows is the name of the
value constructor (sometimes called a data
constructor)
- After
Book
, the Int,
String, and [String] that follow are
the components of the type.