www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [theory] What is a type?

reply Justin Johansson <no spam.com> writes:
Specifically I have a problem in trying to implement
a functional language translator in D.  My target language
has a rather non-conventional type system, in which,
superficially at least, types can be described as being
Cartesian in nature. That is,
types in this system have two orthogonal dimensions:
(1) classical data-type (e.g. boolean, number, string,
object) and
(2) Kleene cardinality (occurrences) with respect to (1).

The axial origin of this Cartesian type-system correlates well
with the concept of the "top" type (AKA "Unit" in Scala)
and as the rather adhoc "void" type in many Algol-derived
languages such as C/C++/Java/D.

So along axis 1 we might broadly describe the classical
data types as item, boolean, number, string, object where
item is effectively either a superclass or variant of the
other mentioned types.

Along axis 2 we describe Kleene occurrences of 1 as may be
passed contractually to a receiving function.  These
occurrences may be enumerated six-fold as:
zeroOrMore
zeroOrOne
oneOrMore
exactlyZero
exactlyOne
none

Readers may see that, for example, zeroOrOne is a special
case (perhaps a subclass?) of zeroOrMore.  exactlyOne is
a special case of both zeroOrOne and oneOrMore (sounds like
multiple inheritance?).  OTOH, exactlyZero is a special
case of zeroOrOne, which, in turn, is a special case of
zeroOrmore.

none is a special case of all of the above and reflects
the cardinality facet of the return type of a function
that never returns (say as by throwing an exception).

To make this type system even more enigmatic lets add a
third dimension, taking the 2-D Cartesian type system
model to a 3-D Spatial model, by imagining a further
degree of freedom with respect to laziness of evaluation
(AKA closure of arguments).

Now having hopefully described that a type is something
that might well have multiple orthogonal aspects to its
identity, how would one go about implementing a dynamic
language with such a complex type system in D?

I realize that this is a complex topic and that it might
require better articulation than so far I have given.

Nevertheless, thanks for all replies,
Justin Johansson
Oct 10 2010
parent reply "Manfred_Nowak" <svv1999 hotmail.com> writes:
Justin Johansson wrote:
 These occurrences may be enumerated six-fold as:

These are three dimensions already. -manfred
Oct 10 2010
parent reply Justin Johansson <no spam.com> writes:
On 11/10/2010 4:10 AM, Manfred_Nowak wrote:
 Justin Johansson wrote:
 These occurrences may be enumerated six-fold as:

These are three dimensions already. -manfred

Sorry, perhaps a miscommunication, the six-fold occurrence types are enumerated along one axis (the cardinality axis). Why do you mention there are three dimensions already wherein my model there are just three dimensions anyway? - JJ
Oct 12 2010
parent "Manfred_Nowak" <svv1999 hotmail.com> writes:
Justin Johansson wrote:

 the six-fold occurrence types

6= 8-2= 2^3-2 You modeled three axis into one enumeration. The three boolean axis are `zero', `one', `more'. Because `more' cannot exist without `one' two entries in your enumeration are discarded. -manfred
Oct 12 2010