Sets vs. Arrays

Coordinator
Dec 13, 2010 at 3:30 PM

NeturalMath needs to support the concept of mathematical sets, but how similar should these be to an array?  In traditional programming languages, arrays are usually independent from a "set" concept.  In .NET this is represented by the difference between an array and an ArrayList.  Commonly in programming, as in math, arrays are of a single data type, while sets may be different types of data.  Furthermore, arrays are always of a fixed length, while sets can sometimes be modified.  Again, in .NET this is the difference between an array and a collection or list.

NeturalMath uses a dynamic typing system which does not focus on an individual variable's data type, but instead allows it to interoperate with every other type in some form.  That would tend to indicate that differentiating sets from arrays by stating that an array consists of a single data type while a set is mixed doesn't really apply.  Furthermore, since all data types in NM are immutable, you cannot directly modify a set or an array--you will get back a new object with whatever modifications were made.  This breaks down the immutable array/ mutable set argument and also renders it meaningless.

Where the real problems arise is in the syntax for declaring a set, how it behaves in operations, and how it is differentiated from other language constructions by the parser.

Currently, the curly braces ({}) represent a domain and square brackets ([]) represent sets.  It has been pointed out that in mathematics, sets are represented by curly braces and arrays by square brackets.  As stated earlier, sets and arrays have no real fundamental difference in NeturalMath, therefore we really only need to represent one concept.  Curly braces are typically used in programming languages to represent scope, so it is natural to use them for domains, which control scope in NM.  What makes the most sense?  Are there reasons which have not been considered why sets and arrays should be separate concepts?  Is it possible to reuse the curly braces for both sets and domains without ambiguity?