Project Inquiry

Email to String

Challenge
{-# LANGUAGE NoImplicitPrelude #-}

module Main where

import           Prelude

main :: IO ()
main = putStrLn $ if test then "SUCCESS" else "FAILURE"

data Email = Email { name :: String, domain :: String }

test :: Bool
test = and [ show (Email "tony" "stark.com") == "tony@stark.com"
           , show (Email "Tony" "Stark.com") == "Tony@Stark.com"
           ]

-- TODO: This program doesn't compile. Define the missing function(s) incl. type signatures!
Solution
{-# LANGUAGE NoImplicitPrelude #-}

module Main where

import           Prelude

main :: IO ()
main = putStrLn $ if test then "SUCCESS" else "FAILURE"

data Email = Email { name :: String, domain :: String }

test :: Bool
test = and [ show (Email "tony" "stark.com") == "tony@stark.com"
           , show (Email "Tony" "Stark.com") == "Tony@Stark.com"
           ]

-- DONE
instance Show Email where
  show email = name email <> "@" <> domain email