From faa1ff3941411d88ef75e0562de4dfd7aa3b68c4 Mon Sep 17 00:00:00 2001 From: Hammy Date: Mon, 5 Apr 2021 03:36:18 +0100 Subject: [PATCH] Compare using inbuilt compare function --- Unit 1/Lesson 4/customSorting.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Unit 1/Lesson 4/customSorting.hs b/Unit 1/Lesson 4/customSorting.hs index ebd36e3..9d5a9b2 100644 --- a/Unit 1/Lesson 4/customSorting.hs +++ b/Unit 1/Lesson 4/customSorting.hs @@ -1,6 +1,16 @@ import Data.List (sort, sortBy) import AllNames (names) +compareSurnameWithCompareFunction :: (Ord a1, Ord a2) => (a1, a2) -> (a1, a2) -> Ordering +compareSurnameWithCompareFunction name1 name2 = if result == EQ + then compare forename1 forename2 + else result + where surname1 = snd name1 + surname2 = snd name2 + forename1 = fst name1 + forename2 = fst name2 + result = compare surname1 surname2 + compareSurname :: Ord a1 => (a2, a1) -> (a3, a1) -> Ordering compareSurname name1 name2 = if surname1 > surname2 then GT