tabulators

Stephen Weeks MLton@sourcelight.com
Tue, 5 Feb 2002 09:59:07 -0800


> As a side comment, while we could certainly add mapTo2 to the Vector
> structure as things exist now, I actually think that from a design
> stand-point it doesn't belong there.  A quick look at the signature
> suggests that just about everything there can be done with exactly one
> pass over the input vector and directly accumulate the result (as in a
> fold) or simultaneously produce the result vector (using unfoldi).  So,
> adding something like mapTo2 gives the "illusion" that it is more
> efficient than it really is.

I don't understand this reasoning.  What is map2 other than a mild
generalization of unzip, which is in the signature already?

fun unzip v = map2 (v, fn z => z)

This would be better than what we currently have, since it would make
only one pass over the input vector.  map2 also makes one pass over
each output vector, which doesn't seem illusory to me.

> Even further afield, I am somewhat irked by the fact that I can't write a
> signature like:
> 
> val map{N}To{M} : ('a1 t * ... * 'a{N} t * 'a -> ('b1 * ... * 'b{M})) ->
>                   ('bt t * ... * 'b{M} t)
> 
> and be able to use map1To3 and map10To2 without changing the library
> and/or making some "arbitrary" choice of what functions should be provided
> by the library.

I agree.  I have long thought that the SML notation and type system
(and hence our libraries) for lists/sets/vectors is too restrictive.
I think there is a lot of room for improvement with a new syntax, type
system, and compiler support for efficient map/fold/construct/...