O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

  1. We defined Product1 with one data constructor Product1 :: Bool -> Product1. How many values can we construct for Product1? Since it takes Bool, it can have two values Product1 True and Product1 False. This is the simplest product type that we have defined.
  1. Next, we defined a data type Product2Product2's constructor takes two Bool values. For Product2, we can construct four values. Please refer to the following table:
    Product2 fields Bool Bool
    Product2 True True
    Product2 True False
    Product2 False True
    Product2 False True

    Note that we have four values for Product2.  Also, note that we constructed Product2 by adding one more Bool field to Product1. For each possible value of Product1, we have two possible values ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required