- 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"
- 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
- Note the indentation. Since it is part of the same function main, the indentation should match the putStrLn "Using Maybe" line.
- Use the isJust function to check ...