[Nickle]Re: structure compatibility (was: I'm confused about type promotion)

Jamey Sharp nickle@nickle.org
24 Jul 2002 14:05:36 -0700


On Wed, 2002-07-24 at 06:19, Carl Worth wrote:
> What prompted my train of thought was the surprising behavior of the
> "structure compatibility rule" mentioned in the nickle tutorial,
> (which is coming along quite nicely by the way -- thanks!):
> 
> 	a struct value is compatible with a struct type if
> 	the struct value contains all of the entries in the
> 	type.

This sounds to me like a horrible misfeature.

In XCB, we had to do non-idiomatic single-element structures to get C's
type system to properly check XIDs.

It sounds like even that is complicated by nickle's type system,
requiring the programmer to ensure that no other structure has a field
of the same name. Doesn't this mean that "XCB-Nickle" would need types
with horrible long element names like these?

typedef struct {
  int XCBFONTSeqnum;
} FONT;

typedef struct {
  int XCBWINDOWSeqnum;
} WINDOW;

And doesn't it mean that even with this effort, some library developer
down the line could introduce serious type-safety errors into XCB?

Promotion between structure types considered harmful, in short, unless
the language allows the programmer to say explicitly that two structure
types are related.
-- 
Jamey Sharp <jamey@sharp.ath.cx> - http://jamey.is.dreaming.org/