
In-Reply-To: Hamilton Richards's message of Fri, 7 Dec 2001 12:11:23 -0600
In my previous example,
t = [0..] b = 3 : t c = 5 : t
lists b and c share t, but in
x = 3 : [0..] y = 5 : [0..]
lists x and y share nothing. Extensionally, they have the same values as b and c, but each has its own copy of [0..].
That's because you're interpreting "same value" extensionally. The same sort of issue comes up in Lisp or Java. But suppose in Java I have Object x = new Whatever(); and that new object has some large substructures. I can get one of those substructures to be shared, rather than copied, without having a variable whose value is that substructure. For instance, the substructure might be shared in Object[] anArray = new Object[](x.getSubstructure(), x.getSubstructure()); provided that x.getSubstructure() returns the very same substructure (not a copy) each time.
Unless, that is, the compiler is clever enough to recognize the subexpression [0..] which x and y have in common. I don't know whether any Haskell compilers look for common subexpressions, but it's certainly an option. So the question of whether names are "*the* (only) way" to obtain sharing isn't really a language question-- it's more of a compiler question.
Are they the only way that's guaranteed to result in sharing, or is even that not the case? Cheers, Jeff