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
|
module Employee where
import Data.Tree
-- Employee names are represented by Strings.
type Name = String
-- The amount of fun an employee would have at the party, represented
-- by an Integer
type Fun = Integer
-- An Employee consists of a name and a fun score.
data Employee = Emp { empName :: Name, empFun :: Fun }
deriving (Show, Read, Eq)
-- A small company hierarchy to use for testing purposes.
testCompany :: Tree Employee
testCompany
= Node (Emp "Stan" 9)
[ Node (Emp "Bob" 2)
[ Node (Emp "Joe" 5)
[ Node (Emp "John" 1) []
, Node (Emp "Sue" 5) []
]
, Node (Emp "Fred" 3) []
]
, Node (Emp "Sarah" 17)
[ Node (Emp "Sam" 4) []
]
]
testCompany2 :: Tree Employee
testCompany2
= Node (Emp "Stan" 9)
[ Node (Emp "Bob" 3) -- (8, 8)
[ Node (Emp "Joe" 5) -- (5, 6)
[ Node (Emp "John" 1) [] -- (1, 0)
, Node (Emp "Sue" 5) [] -- (5, 0)
]
, Node (Emp "Fred" 3) [] -- (3, 0)
]
, Node (Emp "Sarah" 17) -- (17, 4)
[ Node (Emp "Sam" 4) [] -- (4, 0)
]
]
-- A type to store a list of guests and their total fun score.
data GuestList = GL [Employee] Fun
deriving (Show, Eq)
instance Ord GuestList where
compare (GL _ f1) (GL _ f2) = compare f1 f2
|