summaryrefslogtreecommitdiff
path: root/lec08/Party.hs
diff options
context:
space:
mode:
authorEdoardo La Greca2025-10-05 02:50:46 +0200
committerEdoardo La Greca2025-10-05 02:50:46 +0200
commit874abc5ad5a6b8ea74db6386eeede5a244e00673 (patch)
treef601980671e1eb5897231f2cf04cb540fbb2d4b6 /lec08/Party.hs
parent0bfe07508bd60cef9edcc249fe24d7d6a96492c8 (diff)
add fifth exercise of lecture 8
Diffstat (limited to 'lec08/Party.hs')
-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