]> git.rkrishnan.org Git - yorgey.git/blobdiff - hw8/Party.hs
hw12: exercise 4
[yorgey.git] / hw8 / Party.hs
index 3bc5e1b448b84b399c4101b26305152637f6c197..0ca0e1e9e06be3b2fffe92eca044f10ad18e466b 100644 (file)
@@ -4,6 +4,7 @@ module Party where
 import Data.Monoid
 import Employee
 import Data.Tree
+import qualified Data.List as L
 
 -- exercise 1
 -- glCons - a naive way to add an employee to a guest list
@@ -60,3 +61,19 @@ maxFun = uncurry moreFun . maxFunPair
 maxFunPair :: Tree Employee -> (GuestList, GuestList)
 maxFunPair (Node e es) = nextLevel e $ map maxFunPair es
 
+-- exercise 5
+-- main
+
+sortedGL :: GuestList -> (Integer, [String])
+sortedGL (GL empls funval) = (funval, L.sort $ map empName empls)
+
+getEmployeeList :: String -> String
+getEmployeeList empls = let (f, ls) = sortedGL (maxFun (read empls))
+                        in
+                          unlines $ show f : ls
+
+main :: IO ()
+main = do
+  -- empls <- readFile "company.txt"
+  emplList <- fmap getEmployeeList (readFile "company.txt")
+  putStrLn emplList