Concept

How are sets different from computer collections in size and type?

Stephen Davies, Ph.D. Version 2.2.2 Through Discrete Mathematics A Cool Brisk Walk / Chapter 1

"Infinite sets. ’Nuff said. I’ve never seen an array with infinitely many elements, and neither will you. Untyped. Most of the time, an array or other collection in a computer program contains elements of only a single type: it’s an array of integers, or a linked list of Customer objects, for example. This is important because the program often needs to treat all elements in the collection the same way. Perhaps it needs to loop over the array to add up all the numbers, or iterate through a customer list and search for customers who have not placed an order in the last six months. The program would run into problems if it tried to add a string of text to its cumulative total, or encountered a Product object in the middle of its list of Customers. Sets, though, can be heterogeneous, meaning they can contain different kinds of things. The Davies family example had all human beings, but nothing stops me from creating a set X = { Jack Nicholson, Kim Kardashian, Universal Studios, 5786, F }. I don’t press this point too hard for a couple of reasons. First, most programming languages do allow heterogeneous collections of some sort, even if they’re not the most natural thing to express. In Java, you can define an ArrayList as a non-generic so that it simply holds items of class “Object”. In C, you can have an array of void *’s — pointers to some unspecified type — which allows your array to point to different kinds of things. Unless it’s a loosely-typed language, though, like Perl or JavaScript, it sort of feels like you’re bending over backwards to do this. The other reason I make this distinction lightly is that when we’re dealing with sets, we often do find it useful to deal with things of only one type, and so our Ω ends up being homogeneous anyway."

Related Ideas

How are sets different from computer collections in size and type? | Stephen Davies, Ph.D. Version 2.2.2 Through Discrete Mathematics A Cool Brisk Walk | Bifalgorithm | Bifalgorithm