]> git.rkrishnan.org Git - yorgey.git/blob - hw8/Party.hs
180e45a49c32b44fcf389722d0192633ccb27d24
[yorgey.git] / hw8 / Party.hs
1 {-# OPTIONS_GHC -Wall -fno-warn-orphans #-}
2 module Party where
3
4 import Data.Monoid
5 import Employee
6
7 -- exercise 1
8 -- glCons - a naive way to add an employee to a guest list
9 glCons :: Employee -> GuestList -> GuestList
10 glCons e@(Emp {empFun = funval}) (GL els fun) = GL (e:els) (fun + funval)
11
12 -- Monoid instance for GuestList
13 instance Monoid GuestList where
14   mempty = GL [] 0
15   (GL el1 f1) `mappend` (GL el2 f2) = GL (el1 ++ el2) (f1 + f2)
16
17 -- moreFun
18 moreFun :: GuestList -> GuestList -> GuestList
19 moreFun g1@(GL _ f1) g2@(GL _ f2) | f1 > f2 = g1
20                                   | otherwise = g2