summaryrefslogtreecommitdiff
path: root/lec08
diff options
context:
space:
mode:
Diffstat (limited to 'lec08')
-rw-r--r--lec08/Party.hs27
1 files changed, 27 insertions, 0 deletions
diff --git a/lec08/Party.hs b/lec08/Party.hs
index 744d3e4..bc2150e 100644
--- a/lec08/Party.hs
+++ b/lec08/Party.hs
@@ -2,6 +2,7 @@ module Party where
import Employee
import Data.Tree
+import Data.List
-- Exercise 1
@@ -72,3 +73,29 @@ nextLevel boss outcomes = (bestWith, bestWithout)
maxFun :: Tree Employee -> GuestList
maxFun hierarchy = maximum $ treeFold nextLevel hierarchy
+
+-- Exercise 5
+
+glBare :: GuestList -> [Employee]
+glBare (GL empList _) = empList
+
+glFun :: GuestList -> Fun
+glFun (GL _ fun) = fun
+
+readEmpTree :: String -> Tree Employee
+readEmpTree = read
+
+names :: GuestList -> [String]
+names = map empName . sortOn empName . glBare
+
+printNames :: [String] -> IO ()
+printNames = foldl1' (>>) . map putStrLn
+
+printTotal :: GuestList -> IO ()
+printTotal gl = putStrLn $ "Total fun: " ++ show (glFun gl)
+
+printAll :: GuestList -> IO ()
+printAll gl = printTotal gl >> printNames (names gl)
+
+main :: IO ()
+main = readFile "company.txt" >>= printAll . maxFun . readEmpTree