Friday, September 07, 2007

Types to distinguish parameters and dimensions

Suppose a language had a rule that said a function could only have one parameter of a given type, and each dimension of a multidimensional array had to be indexed by a different type.

This would have several benefits:

  1. You'd get extra fine-grained checking; you couldn't possibly get parameters mixed up
  2. When making array slices or currying, you wouldn't have to concern yourself with the ordering of the parameters.
  3. You wouldn't need to distinguish between optional named parameters and ordinal parameters. The name of a parameter would be (or would be derived from) it's type.
With functions like + that seem to require two items of the same type, you could interpret the two (or more) arguments as a collection. Lists certainly could contain homogeneously typed members.