Created
May 9, 2017 14:42
-
-
Save denisshevchenko/beac9ee105d939f055aaddf2c44c1300 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Data.Text ( Text ) | |
type Name = Text | |
type Age = Int | |
type Citizenship = Text | |
type GoalCountry = Text | |
data Ticket = Ticket | |
{ customerFullName :: Name | |
, customerAge :: Age | |
, customerCitizenship :: Citizenship | |
, customerGoalCountry :: GoalCountry | |
, additionalInfo :: TicketAdditionalInfo | |
} | |
data TicketAdditionalInfo = TicketAdditionalInfo | |
{ visaRequired :: Bool | |
} | |
orderTicket :: Name -> Age -> Citizenship -> GoalCountry -> Maybe Ticket | |
orderTicket fullName age citizenship goalCountry = maybeTicket | |
where | |
maybeTicket = | |
if custorerIsEnoughOld | |
then Just ticket | |
else Nothing | |
ticket = Ticket { customerFullName = fullName | |
, customerAge = age | |
, customerCitizenship = citizenship | |
, customerGoalCountry = goalCountry | |
, additionalInfo = addInfo | |
} | |
addInfo = TicketAdditionalInfo { visaRequired = checkGoalCountry | |
} | |
custorerIsEnoughOld :: Bool | |
custorerIsEnoughOld = age >= 18 | |
checkGoalCountry :: Bool | |
checkGoalCountry = goalCountry == "USA" | |
main :: IO () | |
main = putStrLn $ do | |
let ticketBox = orderTicket "Denis Shevchenko" 36 "Russia" "Armenia" | |
case ticketBox of | |
Nothing -> "Sorry, your ticket is gone!" | |
Just ticket -> | |
if visaRequired . additionalInfo $ ticket | |
then "Sorry, you need visa to visit this country." | |
else "Hey yo! Welcome to our country!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment