Lean4
/-- `uniquify L` takes a list `L : List α` as input and it returns a list `L' : List (α × ℕ)`.
The two lists `L` and `L'.map Prod.fst` coincide.
The second component of each entry `(a, n)` in `L'` is the number of times that `a` appears in `L`
before the current location.
The resulting list of pairs has no duplicates.
-/
def uniquify : List α → List (α × ℕ)
| [] => []
| m :: ms =>
let lms := uniquify ms
(m, 0) :: (lms.map fun (x, n) => if x == m then (x, n + 1) else (x, n))