]> git.rkrishnan.org Git - yorgey.git/blob - hw8/Employee.hs
hw8: starting material
[yorgey.git] / hw8 / Employee.hs
1 module Employee where
2
3 import           Data.Tree
4
5 -- Employee names are represented by Strings.
6 type Name = String
7
8 -- The amount of fun an employee would have at the party, represented
9 -- by an Integer
10 type Fun  = Integer
11
12 -- An Employee consists of a name and a fun score.
13 data Employee = Emp { empName :: Name, empFun :: Fun }
14   deriving (Show, Read, Eq)
15
16 -- A small company hierarchy to use for testing purposes.
17 testCompany :: Tree Employee
18 testCompany
19   = Node (Emp "Stan" 9)
20     [ Node (Emp "Bob" 2)
21       [ Node (Emp "Joe" 5)
22         [ Node (Emp "John" 1) []
23         , Node (Emp "Sue" 5) []
24         ]
25       , Node (Emp "Fred" 3) []
26       ]
27     , Node (Emp "Sarah" 17)
28       [ Node (Emp "Sam" 4) []
29       ]
30     ]
31
32 testCompany2 :: Tree Employee
33 testCompany2
34   = Node (Emp "Stan" 9)
35     [ Node (Emp "Bob" 3) -- (8, 8)
36       [ Node (Emp "Joe" 5) -- (5, 6)
37         [ Node (Emp "John" 1) [] -- (1, 0)
38         , Node (Emp "Sue" 5) [] -- (5, 0)
39         ]
40       , Node (Emp "Fred" 3) [] -- (3, 0)
41       ]
42     , Node (Emp "Sarah" 17) -- (17, 4)
43       [ Node (Emp "Sam" 4) [] -- (4, 0)
44       ]
45     ]
46
47 -- A type to store a list of guests and their total fun score.
48 data GuestList = GL [Employee] Fun
49   deriving (Show, Eq)
50
51 instance Ord GuestList where
52   compare (GL _ f1) (GL _ f2) = compare f1 f2