From: Ramakrishnan Muthukrishnan Date: Thu, 25 Dec 2014 14:50:35 +0000 (+0530) Subject: hw8: exercise 1 solutions X-Git-Url: https://git.rkrishnan.org/specifications/%5B/%5D%20/%22doc.html/%22file://%22%3C?a=commitdiff_plain;h=4047fa7672c3cc0b39885f223a05c2540954d197;p=yorgey.git hw8: exercise 1 solutions --- diff --git a/hw8/Party.hs b/hw8/Party.hs new file mode 100644 index 0000000..180e45a --- /dev/null +++ b/hw8/Party.hs @@ -0,0 +1,20 @@ +{-# OPTIONS_GHC -Wall -fno-warn-orphans #-} +module Party where + +import Data.Monoid +import Employee + +-- exercise 1 +-- glCons - a naive way to add an employee to a guest list +glCons :: Employee -> GuestList -> GuestList +glCons e@(Emp {empFun = funval}) (GL els fun) = GL (e:els) (fun + funval) + +-- Monoid instance for GuestList +instance Monoid GuestList where + mempty = GL [] 0 + (GL el1 f1) `mappend` (GL el2 f2) = GL (el1 ++ el2) (f1 + f2) + +-- moreFun +moreFun :: GuestList -> GuestList -> GuestList +moreFun g1@(GL _ f1) g2@(GL _ f2) | f1 > f2 = g1 + | otherwise = g2