Note that if List contains only ground terms, it cannot contain proper instances or variants, but only duplicates. Therefore, it is faster to use a sorting predicate to prune it.
Success:
prune_instances([5,2,3,5,4,2],L).
(gives L=[5,2,3,4]).
prune_instances([f(1,2),f(1,M),1],L). % instance
(gives L=[f(1,M),1]).
prune_instances([f(1,2,3),f(1,M,3),f(1,2,N)],L).
(gives L=[f(1,M,3),f(1,2,N)]).
prune_instances([f(1,N),f(1,M),1],L). % variants (first one retained)
(gives L=[f(1,N),1]).
prune_instances([f(1,X),f(1,2),g(1)],L).
(gives L=[f(1,X),g(1)]).
:- lib(ic).
X::2..5, prune_instances([1,3,X,5,8], L).
(gives L=[X,1,8]).
Fail:
prune_instances([1,2,3,1,4,2],[2,3,4]).