[Swift-devel] Streams

Ben Clifford benc at hawaga.org.uk
Wed May 2 12:54:58 CDT 2012


<begin functional programming ramble - you can tune out now as this is all kinda pie in the sky>

Relevant (at a language design level) to the problem of arrays getting almost-infinitely big and how to garbage collect.

When you write:

output = map f input

then f is applied element at a time.

The code in f doesn't do the indexing into 'input' or 'output' itself - instead the language handles that inside 'map'.

What makes that interesting in this case is that you can change input/output to be something that isn't an indexable array - a "stream", for example.

So the function f can only ever deal with the 'current position' in the stream - it can't go off trying to access either the future or the past.

Which means, then, that the runtime system can assume more about how data will be used, and what it can forget about - once "now" has been processed completely, then the runtime can forget about "now".

The application code can't go back and refer to the past. But that's sort of the point...

There are other things on top of this to allow bounded access to the past so that you can do things like compare to the previous timestep, but they are bounded so that the runtime can still make useful inferences about when data is no longer needed.

-- 




More information about the Swift-devel mailing list