diff options
| author | Edoardo La Greca | 2025-09-25 20:07:20 +0200 |
|---|---|---|
| committer | Edoardo La Greca | 2025-09-25 20:15:37 +0200 |
| commit | 1ca06ff0e1d16586c9ae32baa55988c72aee7b2e (patch) | |
| tree | 153555501de75412cea3f360c61f74073a21810d /lec08 | |
| parent | 918bd7290c89a87dbb09bd192626f364a3b4c980 (diff) | |
add first exercise of lecture 8
Diffstat (limited to 'lec08')
| -rw-r--r-- | lec08/Party.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lec08/Party.hs b/lec08/Party.hs new file mode 100644 index 0000000..4ac241b --- /dev/null +++ b/lec08/Party.hs @@ -0,0 +1,20 @@ +module Party where + +import Employee + +-- Exercise 1 + +glCons :: Employee -> GuestList -> GuestList +glCons e { empFun = ef } (GL es cf) = GL (e:es) (cf + ef) + +-- mappend (a.k.a. (<>)) has been moved to Semigroup +instance Semigroup GuestList where + (<>) (GL es1 f1) (GL es2 f2) = GL (es1 ++ es2) (f1 + f2) + +instance Monoid GuestList where + mempty = GL [] 0 + +moreFun :: GuestList -> GuestList -> GuestList +moreFun gl1@(GL _ f1) gl2@(GL _ f2) + | f1 >= f2 = gl1 + | otherwise = gl2 |