How to do it...

  1. Open src/Main.hs. We will experiment in the main function in this file. Replace the main function with following content:
        main :: IO ()        main = do        putStrLn "Using Maybe"
  1. Continue in the same function. Start defining various values of Maybe. Maybe is a sum type that may contain a value. The data constructor Just takes the value, whereas the constructor Nothing represents the absence of any value. Define three instances of the Maybe value, representing integral values 10, 2, and 0:
        let i = Just 10 :: Maybe Int        j = Just 2 :: Maybe Int        z = Just 0 :: Maybe Int
  1. Note the indentation. Since it is part of the same function main, the indentation should match the putStrLn "Using Maybe" line. 
  1. Use the isJust function to check ...

Get Haskell Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.