]> git.rkrishnan.org Git - yorgey.git/commitdiff
hw8: exercise 1 solutions
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Thu, 25 Dec 2014 14:50:35 +0000 (20:20 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Thu, 25 Dec 2014 14:50:35 +0000 (20:20 +0530)
hw8/Party.hs [new file with mode: 0644]

diff --git a/hw8/Party.hs b/hw8/Party.hs
new file mode 100644 (file)
index 0000000..180e45a
--- /dev/null
@@ -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