From 874abc5ad5a6b8ea74db6386eeede5a244e00673 Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Sun, 5 Oct 2025 02:50:46 +0200 Subject: add fifth exercise of lecture 8 --- lec08/Party.hs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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 -- cgit v1.2.3