hist :: (Ord e, LL.ListLike l e) => l -> [(e, Int)]
hist l
  | LL.null l = []
  | otherwise = let l' = LL.sort l in hist' [] (LL.head l') 1 (LL.tail l')
  where
    hist' res e cnt l
      | LL.null l = (e, cnt) : res
      | otherwise =
        let (e', l') = (LL.head l, LL.tail l)
        in if e == e'
           then hist' res e (cnt+1) l'
           else hist' ((e, cnt) : res) e' 1 l'
hist :: (Ord e, LL.ListLike l e) => l -> [(e, Int)]
hist l
  | LL.null l = []
  | otherwise = let l' = LL.sort l in hist' [] (LL.head l') 1 (LL.tail l')
  where
    hist' res e cnt l
      | LL.null l = (e, cnt) : res
      | otherwise =
        let (e', l') = (LL.head l, LL.tail l)
        in if e == e'
           then hist' res e (cnt+1) l'
           else hist' ((e, cnt) : res) e' 1 l'
hist l
  | LL.null l = []
  | otherwise = let l' = LL.sort l in hist' [] (LL.head l') 1 (LL.tail l')
  where
    hist' res e cnt l
      | LL.null l = (e, cnt) : res
      | otherwise =
        let (e', l') = (LL.head l, LL.tail l)
        in if e == e'
           then hist' res e (cnt+1) l'
           else hist' ((e, cnt) : res) e' 1 l'