= Solution
Represent the ranking criteria by a <tuple> in decreasing priority:
``
type Weight = (Int,Int,Int)
weight :: Results -> Weight
weight (Results _ scores) =
(sum (map points scores),
sum [gf - ga | (gf,ga) <- scores],
sum (map fst scores))
where
points (gf,ga)
| gf > ga = 3
| gf == ga = 1
| otherwise = 0
``
The components are \b[total points, total goal difference and total goals scored]. The <Haskell Ord class> compares <tuples> in <lexicographic order>, so a greater first component dominates all later components; only ties reach the next criterion. Exactly equal triples remain tied because no further ranking criterion was specified. In the supplied fixture data the descending triples are $(6,13,15)$, $(4,3,5)$, $(3,0,3)$, $(1,0,0)$, $(1,-3,4)$, $(1,-3,0)$ and $(0,-10,0)$, respectively for United, Athletic, City, Albion, Rovers, Corinthians and Thistle.
Back to article page