First-occurrence duplicate removal (source code)

= First-occurrence duplicate removal

Retain the first occurrence of each distinct value in a <list>. The <right fold> `foldr (\x ys -> x : filter (/= x) ys) []` preserves this order under <lazy evaluation>. With terminating <equality tests>, an infinite input containing infinitely many distinct values produces every finite output prefix. If only finitely many distinct values occur, those values appear but the remaining infinite input cannot generally be certified empty: the result has an undefined tail rather than a terminating empty <list>.