Skip to content

Instantly share code, notes, and snippets.

@manuelsidler
Last active August 5, 2019 20:01
Show Gist options
  • Save manuelsidler/eca9807b87edbeb1fdbf84f6445d9eba to your computer and use it in GitHub Desktop.
Save manuelsidler/eca9807b87edbeb1fdbf84f6445d9eba to your computer and use it in GitHub Desktop.
type CheckNumber = CheckNumber of int
type CardNumber = CardNumber of int
type CardType =
| Visa
| Mastercard
type CreditCard = {
CardType : CardType
CardNumber : CardNumber
}
type PaymentMethod =
| Cash
| Check of CheckNumber
| Card of CreditCard
type PaymentAmount = PaymentAmount of decimal
type Currency =
| EUR
| CHF
| USD
type Priority =
| High
| Medium
| Low
type Payment = {
Amount : PaymentAmount
Currency : Currency
Method : PaymentMethod
Priority : Priority option
}
let printPaymentMethod payment =
match payment.Method with
| Cash -> printfn "Cash"
| Check checkNumber -> printfn "Check %A" checkNumber
| Card card ->
match card.CardType with
| Visa -> printfn "Visa"
| Mastercard -> printfn "Mastercard"
payment
let handlePayment payment =
match payment.Priority with
| Some priority when priority = High -> printfn "Express payment"
| Some _ -> printfn "Normal payment"
| None -> printfn "No priority"
payment
let payment = {
Amount = PaymentAmount 5.50m
Currency = EUR
Method = Card { CardType = Visa; CardNumber = (CardNumber 13371234); }
Priority = Some High
}
payment |> printPaymentMethod |> handlePayment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment