setof(Template, Goal, Instances) is equivalent to bagof/3, but it also applies sort/2 to the result.