[q-lang-users] Subtypes and Interfaces
Brought to you by:
agraef
From: Rob H. <hub...@gm...> - 2007-06-09 02:00:56
|
Hello Albert, This is probably not a good time to pose questions unrelated to the imminent 7.7 release. Sorry. Suppose I have (parametrised) types public type T1 = private const nil F; public type T2 : T1; // a variant with special meaning I can define constructors and tests for T1: public empty_t1 F; public is_t1 T; empty_t1 F = nil F; is_t1 _:T1 = true; is_t1 _ = false; Now I wish to define constructors and tests for T2: public empty_t2 F; public is_t2 T; private adjust F; adjust F = (F . fst); // for example empty_t2 F = empty_t1 (adjust F); // *this is not quite right* is_t2 _:T2 = true; is_t2 _ = false; Thus a T2 is also a T1, but the constructor makes some adjustments to the interface. My question is: is there a way to "cast" the result of the constructor empty_t2 so that the object returned is a T2? What I want is for these both to return true: is_t1 (empty_t2 my_func); is_t2 (empty_t2 my_func); At the moment only the first does. I want to take advantage of the fact that all the T1 code will work on T2 objects without having to repeat all the T1 code, and I don't think I want to wrap the T1 within T2 (in C++ terminology, I want T2 to inherit from T1 rather than to have a T1 member datum; so T2 "is a" T1, but not T2 "has a" T1). I can't write this: public type T1 = private const nil F; public type T2 : T1 = private const nil F; (in the same file) as this is a conflict for nil. Thanks, Rob. |