summaryrefslogtreecommitdiff
path: root/lec08/Employee.hs
diff options
context:
space:
mode:
authorEdoardo La Greca2025-09-25 20:06:57 +0200
committerEdoardo La Greca2025-09-25 20:06:57 +0200
commit918bd7290c89a87dbb09bd192626f364a3b4c980 (patch)
treeee8da4d9afc02b198f3526290743b161d43b6422 /lec08/Employee.hs
parentf3fe89495ec6922a8825a2eeb61125b87c306e63 (diff)
add files for lecture 8's homework
Diffstat (limited to 'lec08/Employee.hs')
-rw-r--r--lec08/Employee.hs52
1 files changed, 52 insertions, 0 deletions
diff --git a/lec08/Employee.hs b/lec08/Employee.hs
new file mode 100644
index 0000000..c25cbb7
--- /dev/null
+++ b/lec08/Employee.hs
@@ -0,0 +1,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