If `X`

is a set of numbers, then `ΔX`

is a multiset of numbers, representing pairwise subtractions between each 2 numbers. For example, if `X`

is a set of points on a line in increasing order, then `ΔX`

is a multiset of pairwise distances between these points. How to write a function that returns pairwise distances for a list of numbers? The below works, but I want a more elegant solution. Please include theory or intuitions, that might provide insight in how to solve similar problems, if possible.

```
pairwise_distances :: [Int] -> [Int]
pairwise_distances [] = []
pairwise_distances [x] = []
pairwise_distances (x:xs) = sort $ map (abs . (x-)) xs ++ pairwise_distances xs
pairwise_distances [3,2,1] -- [1,1,2]
pairwise_distances [0,2,4,7,10] -- [2,2,3,3,4,5,6,7,8,10]
```