Implement custom sorting methods

main
Hammy 4 years ago
parent 8eccfcfbc4
commit dd3db073db

@ -0,0 +1,8 @@
module AllNames where
names :: [([Char], [Char])]
names = [("Callum", "Kilmartin"),
("Goudham","Suresh"),
("Theo", "Hardman"),
("Luca","Valentini"),
("Cormac", "Muir")]

@ -0,0 +1,22 @@
import Data.List (sort, sortBy)
import AllNames (names)
compareLastNames :: Ord a1 => (a2, a1) -> (a3, a1) -> Ordering
compareLastNames name1 name2 = if surname1 > surname2
then GT
else if surname1 < surname2
then LT
else EQ
where surname1 = snd name1
surname2 = snd name2
-- Using Guards for boolean expressions
-- compareLastNames :: Ord a1 => (a2, a1) -> (a3, a1) -> Ordering
-- compareLastNames name1 name2
-- | surname1 > surname2 = GT
-- | surname1 < surname2 = LT
-- | otherwise = EQ
-- where
-- surname1 = snd name1
-- surname2 = snd name2
Loading…
Cancel
Save