From: Ramakrishnan Muthukrishnan Date: Fri, 26 Dec 2014 09:51:21 +0000 (+0530) Subject: bug fix in moreFun and solution to exercise 3 X-Git-Url: https://git.rkrishnan.org/a?a=commitdiff_plain;h=3086656ce60030952362d7f3814ed2c30e9186a6;p=yorgey.git bug fix in moreFun and solution to exercise 3 --- diff --git a/hw8/Party.hs b/hw8/Party.hs index 2a5cf79..d303b01 100644 --- a/hw8/Party.hs +++ b/hw8/Party.hs @@ -17,8 +17,8 @@ instance Monoid GuestList where -- moreFun moreFun :: GuestList -> GuestList -> GuestList -moreFun g1@(GL _ f1) g2@(GL _ f2) | f1 > f2 = g1 - | otherwise = g2 +moreFun g1 g2 | g1 > g2 = g1 + | otherwise = g2 -- treeFold :: (Tree a -> b -> b) -> b -> Tree a -> b -- treeFold combine e= treeDestructor e f @@ -39,3 +39,15 @@ treeFold f e (Node v []) = f e v treeFold f e (Node v ts) = let b = foldr (\t acc -> treeFold f acc t) e ts in f b v +-- exercise 3 +-- nextLevel +-- if the big boss comes, no question, his reportee managers are not +-- coming. So, we just take the send list from each pair and concat them. +-- if the big boss is not coming, then we pick the list from the pair that +-- has most fun and concat them all. +nextLevel :: Employee -> [(GuestList, GuestList)] -> (GuestList, GuestList) +nextLevel e lst = + let withBoss = glCons e $ mconcat $ map snd lst + withoutBoss = mconcat $ map (uncurry moreFun) lst + in + (withBoss, withoutBoss)