From www@deja.com Mon Feb 14 20:02:37 2000 Message-ID: <889nab$1o9$1@nnrp1.deja.com> From: oleg@pobox.com Subject: Unitary type as a self-referential set Date: Mon, 14 Feb 2000 20:07:43 GMT Reply-To: oleg@pobox.com Keywords: unit, unitary type, datatype constructor, Scheme Newsgroups: comp.lang.scheme,comp.lang.functional Summary: a unitary type in Scheme and its "self-referential" properties X-Article-Creation-Date: Mon Feb 14 20:07:43 2000 GMT Status: OR Several programming languages define a distinguished type that contains only one, special value. An example is a unit datatype () in Haskell, which contains only one non-bottom value, (). Note that the same id labels the type and denotes its only value. Types as sets of values often can be characterized by their constructors -- "generating functions". It is a function whose applications will yield all the possible values of the given type. This observation is trivial for algebraic types in ML and Haskell with one data constructor, for some non-primitive types in C++ and referential types in Java. This is also true of Scheme: a function 'string' for example, can produce all possible strings, including the empty one. The same holds for 'list' and 'vector' [not quite though, see the next post]. It appears interesting to see how to express a unitary type in Scheme, and how its constructor will look like. The answer is surprisingly short: (define (unit) unit) What's more interesting is that (eq? (unit) unit) ==> #t The name of the type and the name of its value are literally the same. In Scheme, a data constructor is a value itself: a procedural value. Therefore, it is a member of some type. It so happens that the constructor of 'unit' is the member of its own type. There is a nice recursive ring to it: a set whose sole element is itself.