On Sunday, 6 April 2014 at 05:27:44 UTC, Josh wrote:
Can anyone please explain why this works:

        auto numbers = sequence!("n")();
auto trimmed = setDifference(setDifference(numbers, sequence!("n * a[0]")(2)), sequence!("n * a[0]")(3));

but this doesn't?

        auto numbers = sequence!("n")();
auto trimmed = setDifference(numbers, sequence!("n * a[0]")(2));
        trimmed = setDifference(trimmed, sequence!("n * a[0]")(3));

Thanks,
Josh

setDifference returns a lazy range, whose type depends on the inputs. It's not just a generic array. Because of this, while these *look* like they are just ranges of numbers:
setDifference(numbers, sequence!("n * a[0]")(2));
setDifference(trimmed, sequence!("n * a[0]")(3));

Their *types* and what goes on under the hood is *complelty* different. Because of this, you can't use the result of the first, to store the result of the second, the types don't match.

Try this:
auto tmpTrimmed = setDifference(numbers, sequence!("n * a[0]")(2)); auto trimmed = setDifference(tmpTrimmed, sequence!("n * a[0]")(3));

Reply via email to