1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import Data.List

lexicalOrder (x1, y1) (x2, y2)
  | x1 < x2   = LT
  | x1 > x2   = GT
  | y1 < y2   = LT
  | y1 > y2   = GT
  | otherwise = EQ

lengthOrder (x1, y1) (x2, y2) = 
  let length x y = sqrt $ x**2 + y**2 in
    compare (length x1 y1) (length x2 y2)

sample = [(1,1), (3,3), (0,0), (0,3), (4,0)]

main = do
  print $ sortBy lexicalOrder sample
  print $ sortBy lengthOrder  sample

-- [(0.0,0.0),(0.0,3.0),(1.0,1.0),(3.0,3.0),(4.0,0.0)]
-- [(0.0,0.0),(1.0,1.0),(0.0,3.0),(4.0,0.0),(3.0,3.0)]