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 to do it...

  1. Open src/Main.hs for editing. 
  2. Add the following data definitions for product types:
        data Product1 = Product1 Bool deriving Show        data Product2 = Product2 Bool Bool deriving Show        data Product3 a = Product3 a Bool deriving Show        data Product4 a b = Product4 a b deriving Show
  1. Change the main function to use the product types defined earlier to create instances, and print their values:
        main :: IO ()        main = do        putStrLn "Product1: Simple product type"        putStrLn $ show $ Product1 True        putStrLn $ show $ Product1 False        putStrLn "Product2: Product type with two fields"        putStrLn "Product2 has two boolean fields. Each one can take          two values each"        putStrLn $ show $ Product2 True True        putStrLn $ show $ Product2 True False putStrLn ...

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