[Nickle]Type narrowing

Keith Packard nickle@nickle.org
Fri, 26 Jul 2002 16:56:31 -0700


Nickle currently has some relatively simplistic type narrowing for
expressions involving 'poly' types.  For example:

	poly i, j;

	i + j;

The addition operator can only generate a few possible types, among them:

	*poly		a;
	int		x, y;
	rational	u, v;
	real		c, d;

	"hello" + "world"	-> string
	a + 1			-> *poly
	x + y			-> int
	u + v			-> rational
	c + d			-> real

Nickle takes advantage of this and narrows the result of 'i + j' to
this list of types; this can be helpful in cases like:

	typedef struct { int i; real r; } s; s sv;

	sv = i + j;

Nickle emits the following error:

 Incompatible types in assignment 's' = 'string, *poly, int, rational, real'

The question is whether this narrowing is reasonable, or whether I should 
just use the single least upper bound type in all cases.

Keith Packard        XFree86 Core Team        HP Cambridge Research Lab