[Swift-devel] Associative array in Swift [GSoC]

Ben Clifford benc at hawaga.org.uk
Tue Jun 21 04:11:32 CDT 2011


On Jun 20, 2011, at 11:44 AM, Mihael Hategan wrote:

> That's some crappy writing, but if I'm reading it right  and in haskell
> lingo:
> 
> map_ ::  (Tk1 Tv1) -> [(Tk2, Tv2)]
> There is an automatic collect_:: [(Tk2, Tv2)] -> (Map Tk2 [Tv2])
> reduce_ :: (Tk2 [Tv2]) -> [Tv3]
> 
> There's an input: (Map Tk1 Tv1) and the system does:
> intermediate = map (map_) toList input
> result = foldl (++) [] map (reduce_) toList collect_ intermediate
> 
> So it does seem like the shapes of the arrays can depend in non-trivial
> ways on the algorithm.

the above looks ok. I think swift arrays can pretty much handle the shapes of array needed. When Tk1 and Tk2, the key types of the input data and intermediate data, are numeric, then swift already has that.

But what would a whole map-reduce like program look like in Swift? Trying to write out a (non-contrived) example of "this is the program that I think I should be able to write, even though Swift can't run it today" would be interesting, perhaps. I found that very interesting when arguing how while loops were useless in Swift all those years ago, and I think there are some interesting issues waiting to be discovered around how you would actually implement a useful map body and reduce body.





More information about the Swift-devel mailing list