[Swift-devel] iterations on cartesian and inner products
Ben Clifford
benc at hawaga.org.uk
Sat Jan 19 12:03:58 CST 2008
On Mon, 14 Jan 2008, Mihael Hategan wrote:
> I'm thinking the following might be nice to have:
>
> X[]
> Y[]
>
> for (x, y) in (X, Y) {
> ...
> }
>
> for (x, y) in (X * Y) {
> ...
> }
Rather than implementing it in the iteration construct, a Haskelly (and
more general) way to do this would be something like this:
i) put anonymously-typed tuples into the language
ii) have proper tuple assignment. we already have this sort-of for
executions, where you can say
(x,y) = foo();
if foo() is a procedure, but not with an expression. So you can't say
(x,y) = @foo()
iii) put the two array product operations into the langauge or library, so
that you can in an expression construct the desired product
iv) make foreach understand tuple assignments - i.e. given an array of
pairs (or n-tuples) assign them in sequence to
I think this would need anonymous tuple types in the language, but I think
I'd like that anyway - as we move towards unifying foo() and @foo() into a
single language construct, I think its desirable to be able to figure
out sensibly what is wrong with
5 + foo()
when foo returns (int a, int b) - i.e. give a type error that (int) is
incompatible with (int,int).
At present, 5 + foo() is a syntax error because you cannot invoke a
procedure inside an expression; but that would go away under foo/@foo
unification.
--
More information about the Swift-devel
mailing list