compareBy

Update: This function is now available in the Data.Ord module under the name comparing.

compareBy :: Ord b => (a -> b) -> a -> a -> Ordering
compareBy f x y = f x `compare` f y

Usage

sortBy (compareBy length) ["abc", "a", "ab"]
 ["a","ab","abc"]