On Wed, Jul 15, 2009 at 2:18 PM, Max Rabkin<[email protected]> wrote:
> On Wed, Jul 15, 2009 at 7:33 PM, Cristiano
> Paris<[email protected]> wrote:
>> fib = 1:1:fib `plus` (tail fib) where plus = zipWith (+)
> ...
> ...
> This indicates that you think tying the knot should be impossible in
> Python. In my opinion this is not the case. By my definition of tying
> the knot, one needs *either* mutable variables or laziness (at least
> in simple cases). Since Python has the former, it is possible to tie
> the knot in Python.
Isn't tying the knot (in the way 'fib' does) straightforward with closures
a la Python/Ruby/Smalltalk (without mutation)?
Even in a syntactically clumsy language like Java, a
tying-the-knot implementation equivalent to the canonical Haskell one is
not difficult, e.g.
static L fibs = new L() {
public int head() { return 1; }
public L tail() {
return new L() {
public int head() { return 1; }
public L tail() {
return new L() {
public int head() { return fibs.head() +
fibs.tail().head(); }
public L tail() { return zip(fibs.tail(),
fibs.tail().tail()); }
};
}
};
}
};
Given a definition of list L and zip...
interface L { int head(); L tail(); }
static L zip(final L l0, final L l1) {
return new L() {
public int head() { return l0.head() + l1.head(); }
public L tail() { return zip(l0.tail(), l1.tail()); }
};
}
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe