unintended type variable instantiation bug fix in ranges_distinct

there are probably more cases of this about. also, the fix here might
not be perfect.