Project Inquiry

String Concatenation

Challenge
{-# LANGUAGE NoImplicitPrelude #-}

module Main where

import           Prelude

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

newtype Name = Name { unName :: String } deriving (Eq)
data Hero = Hero { firstName :: Name, lastName :: Name }

test :: Bool
test = let ironMan = Hero (Name "Tony") (Name "Stark") in
       and [ firstName ironMan == Name "Tony"
           , lastName ironMan == Name "Stark"
           , fullName ironMan == Name "Tony Stark"
           ]

-- 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"

newtype Name = Name { unName :: String } deriving (Eq)
data Hero = Hero { firstName :: Name, lastName :: Name }

test :: Bool
test = let ironMan = Hero (Name "Tony") (Name "Stark") in
       and [ firstName ironMan == Name "Tony"
           , lastName ironMan == Name "Stark"
           , fullName ironMan == Name "Tony Stark"
           ]

-- DONE
fullName :: Hero -> Name
fullName hero = Name $ unName (firstName hero) <> " " <> unName (lastName hero)