[Swift-devel] Standard Library Proposal/Discussion Page

Mihael Hategan hategan at mcs.anl.gov
Wed Jan 21 02:25:11 CST 2015


On Tue, 2015-01-20 at 22:55 -0600, Michael Wilde wrote:
> On 1/20/15 9:59 PM, Ketan Maheshwari wrote:
> > Neat!
> >
> > Comments:
> >
> > -- Statistical functions in a standard library seem out of place to 
> > me. One may ask, why just stop with statistical functions and not also 
> > include vector and matrix related functions such as cross and dot 
> > products or fancier stuff like finding eigen values, etc.
> Important things like sum( ) were placed in this category. I think this 
> is a common need that's hard to do without an intrinsic library 
> function. I suspect there are other frequently encountered needs to 
> iterate through an array and select, count, or otherwise process 
> elements that match some criteria.
> 
> I'd argue for moving such functions to the Array category instead of the 
> stats category. Do we need other types of array reduction functions?  
> min() / max()?  General reduction seems to demand function arguments, 
> but I'm getting beyond my understanding of functional programming here.

So am I. In principle, recursion should be sufficient to do these things
in a functional language. For example, 

min(x[]) = function {
  if (len(x) == 1) {
    return head(x);
  }
  else {
    tmp = min(tail(x));
    return tmp < head(x) ? tmp : head(x);
  }

For starters, we would need a tail() function.

But I don't think we are that language. So I would say that this goes
beyond my understanding too. And this discussion is hopefully going to
fix some of that.

> 
> I wonder what the minimal lowest common denominator intrinsic functions 
> of this nature are, which would enable any higher-level set of stats 
> functions to be implemented. I'm still trying to understand if a 
> necessary and sufficient set of such functions were already included in 
> the proposed set, or if these remain to be defined.

I think your min/max example shows that things remain to be defined,
unless we expect recursive solutions as above to be done by the user.

The array split function was in fact requested by a user and there is a
recursive solution for it. It should be somewhere on swift-user. So why
that and not min/max? I don't know.

Mihael




More information about the Swift-devel mailing list