[Swift-devel] Call function.
Mihael Hategan
hategan at mcs.anl.gov
Fri Aug 12 12:11:38 CDT 2011
On Fri, 2011-08-12 at 16:39 +0000, Ben Clifford wrote:
> What would be needed to write 'map' in swift(script) for use as a library
> function by other swift code? (rather than writing it in karajan or java)
>
> It might look something like this: (standby for bleeding eyes on the first
> line)
>
> (X out[]) map( (X)f(Y), Y inp[]) {
> foreach v,i in inp {
> out[i] = f(v); // or equivalently out[i] = f( inp[i] );
> }
> }
>
> The above adds syntax for passing a function f which takes a value of type
> Y and returns a value of type X. f is invoked by juxtaposition rather than
> by an explicit call, though I think that is irrelevant for this message.
>
> But for map to work for arbitrary 1-d arrays, X and Y need to be type
> variables of some kind, not actual concrete types.
>
> We haven't discussed that at all in this thread, but I think it would be
> needed to do the above kind of thing. That's nothing particularly fancy
> though its another shift away from fortran-era types - C++ templates, java
> generics can both express this in some form, as can haskell.
>
> Comments?
>
True, but we can still cover a lot of cases with:
type mrfile;
type kv {
string key;
mrfile value;
}
(kv[] intermediate) map_((kv[] r) proc(string key, mrfile value), kv[]
input) {
...
}
(mrfile[string][] out2) collect_(kv[] intermediate) {
...
}
(mrfile[] result) reduce_((mrfile[]) proc(mrfile[string]),
mrfile[string][]) {
...
}
I agree though. A full treatment of the issue would require type
parameters.
Mihael
More information about the Swift-devel
mailing list