-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhaskellFun6.hs
More file actions
79 lines (57 loc) · 2.24 KB
/
haskellFun6.hs
File metadata and controls
79 lines (57 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
-- possible pizza toppings
data Topping = Pepperoni | Onions | Ham | Mushrooms | Chicken
deriving (Show)
-- sauces for pizzas and breadsticks
data Sauce = Tomato | Garlic | Pesto
deriving (Show)
-- sizes for pizzas and salads
data Size = Small | Large
deriving (Show)
-- possible dressings for salads
data Dressing = Ranch | Greek | Caesar | None
deriving (Show)
-- items on the menu for purchase
data MenuItem = Breadsticks Sauce
| Salad Size Dressing
| Pizza Size Sauce [Topping]
deriving (Show)
breadsticks1, salad1, pizza1, pizza2 :: MenuItem
order1, order2 :: [MenuItem]
breadsticks1 = Breadsticks Pesto
salad1 = Salad Large Caesar
pizza1 = Pizza Small Garlic []
pizza2 = Pizza Large Tomato [Onions, Pepperoni, Pepperoni, Mushrooms]
order1 = [Salad Large None, Breadsticks Garlic, Pizza Large Tomato []]
order2 = [Pizza Small Tomato [Pepperoni, Mushrooms, Ham, Onions], Salad Small Ranch, Salad Large Greek, Pizza Large Pesto [Ham, Chicken], Breadsticks Garlic]
toppingCost :: Size -> Topping -> Float
toppingCost Small Chicken = 2.50
toppingCost Large Chicken = 3.25
toppingCost Small _ = 1.50
toppingCost Large _ = 2.25
sauceCost :: Size -> Sauce -> Float
sauceCost Small Pesto = 13.25
sauceCost Large Pesto = 16.50
sauceCost Small _ = 11.50
sauceCost Large _ = 14.00
cutCalories :: MenuItem -> MenuItem
cutCalories (Salad _ _) = Salad Small None
cutCalories (Pizza _ s tpg) = Pizza Small s tpg
cutCalories (Breadsticks s) = Breadsticks s
willEat :: MenuItem -> Bool
willEat (Pizza _ Pesto _) = False
willEat (Pizza _ _ xs) = null [ xs | Mushrooms <- xs]
willEat (Breadsticks Pesto) = False
willEat _ = True
price :: MenuItem -> Float
price (Pizza x y zs) = sauceCost x y + sum [ toppingCost x a | a <- zs]
price (Salad Large _) = 9.50
price (Salad Small _) = 6.75
price (Breadsticks _) = 4.25
numToppings :: [MenuItem] -> Int
numToppings xs = sum [ length zs | Pizza a b zs <- xs]
promotion :: [MenuItem] -> Float
promotion [] = 0
promotion [z] = price z
promotion items = sum y - minimum y
where
y = [ price x | x <- items]