|
|
|
|
|
by shachaf
2168 days ago
|
|
No, the article's p takes a function: > type Cantor = Natural -> Bit
> (#) :: Bit -> Cantor -> Cantor
> x # a = \i -> if i == 0 then x else a(i-1) (You could represent bit streams with something like data Stream = Cons Bit Stream in Haskell, of course, but that's not what the article does. The code in the article works in e.g. Python almost as-is.) And you can certainly pass closures to the predicate. Not closing over a mutable variable, of course -- I just mean that the bit stream function itself has to have access to p, which is the trick that makes this possible. If you couldn't do that -- if you could only query it with bit sequences that were defined independently of p -- this wouldn't be possible. |
|
> No, the article's p takes a function
Yeah it does, but it's just misdirection.
A lot of this theory is gamified "you pick YOUR function, THEN I'll pick MINE..." and the order is very important. Here representing sequences as functions only obscures. The important idea is that the sequence is lazy, BUT predetermined. It can't know what the predicate will be. That's where the black magic comes in.
> You could represent bit streams with something like data Stream = Cons Bit Stream in Haskell
I wish it did, it would be much clearer. The article makes that point itself:
"For the type of infinite sequences, we could use the built-in type of lazy lists..."
which is the point you made (which the article dismisses as insufficiently mathematical).
> If you couldn't do that -- if you could only query it with bit sequences that were defined independently of p -- this wouldn't be possible.
No, there's the rub! The bit sequence and `p` are independent. You choose your bit sequence, I choose `p`, and somehow execution finishes. That's exactly what makes this "seemingly impossible."
There is a back-door dependence where `p` forces a lazy sequence to materialize bits, but nothing more. The sequence cannot introspect `p`, and vice-versa.
I think this my third time encountering this post and it took me a few tries to get it!