[Swift-devel] readData2

Ben Clifford benc at hawaga.org.uk
Wed Jul 6 13:28:55 CDT 2011



> > Swift already has a mechanism for specifying the type of a file. Its the 
> > swift type system.
> > 
> >   CSVFile f <"myfile">;
> >   foo = read(f);

> Noope! The structure of a given type is fixed. We want the ability to
> read arbitrary such structures/types from a given format. Also for a
> given type, there can be many formats. So the format is orthogonal to
> the type.

CSVFile is a type that indicates that its file is "a csv file". Its not 
the type of the return value (foo above), which is where the variable 
structure occurs. Whether the file content matches the type of foo, beyond 
being a CSV, is outside of the scope of the "this is a CSV file". That's 
the same, I think, whether you use a mapped CSVFile, or whether you use a 
string: its runtime-read-and-casting a loosely typed thing  (CSVFile or 
string) into a specific data structure.

That reminds me of yet another way that was tossed about once: that the 
mapping between file content and in-memory values should be done by a 
mapper.

So rather than:

int[] foo;
foo = read("myfile", ...):

to read  2,3,5,7,11

you instead write:

int[] foo <csvmapper;fn="myfile",...>

-- 



More information about the Swift-devel mailing list