Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- // ========== Type declaration ==========
- type Drink =
- | Cappuccino // 30 DKK
- | Espresso // 25 DKK
- | Latte // 20 DKK
- | Coke // 15 DKK
- | Sprite // 10 DKK
- | Fanta // 5 DKK
- type Size =
- | Small // 0 DKK
- | Medium // 5 DKK
- | Large // 10 DKK
- type Container =
- | Cup
- | Can
- | Bottle
- type Order = { drink: Drink; size: Size; container: Container }
- // ========== Function for calculating price ==========
- let calculatePrice (p : Order) =
- match p with
- | { drink = Cappuccino; size = Small } -> 30 + 0
- | { drink = Cappuccino; size = Medium } -> 30 + 5
- | { drink = Cappuccino; size = Large } -> 30 + 10
- | { drink = Espresso; size = Small } -> 25 + 0
- | { drink = Espresso; size = Medium } -> 25 + 5
- | { drink = Espresso; size = Large } -> 25 + 10
- | { drink = Latte; size = Small } -> 20 + 0
- | { drink = Latte; size = Medium } -> 20 + 5
- | { drink = Latte; size = Large } -> 20 + 10
- | { drink = Coke; size = Small } -> 15 + 0
- | { drink = Coke; size = Medium } -> 15 + 5
- | { drink = Coke; size = Large } -> 15 + 10
- | { drink = Sprite; size = Small } -> 10 + 0
- | { drink = Sprite; size = Medium } -> 10 + 5
- | { drink = Sprite; size = Large } -> 10 + 10
- | { drink = Fanta; size = Small } -> 5 + 0
- | { drink = Fanta; size = Medium } -> 5 + 5
- | { drink = Fanta; size = Large } -> 5 + 10
- // ========== Test ==========
- let order1 = {drink = Coke; size = Medium; container = Bottle}
- let order2 = {drink = Fanta; size = Medium; container = Can}
- let order3 = {drink = Latte; size = Small; container = Cup}
- let orders = [ order1; order2; order3 ]
- let resultList =
- [
- for i in 0 .. orders.Length - 1 do
- yield calculatePrice orders.[i]
- ]
- let resultSum = List.sum resultList
- printfn "Total price: %d" resultSum
- [<EntryPoint>]
- let main argv =
- printfn "Hello World from F#!"
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement