[q-lang-users] Query about Type Tests (Complex and Rational).
Brought to you by:
agraef
From: Rob H. <hub...@gm...> - 2006-06-15 12:33:21
|
The following are from Albert's complex.q revision 1.5, which is undergoing review at the moment, and my rational.q revision 160. public type Complex : Num; iscomplex _:Complex = true; iscomplex _ = false otherwise; public type Rational : Num; is_rational _:Rational = true; is_rational _ = false; is_rat_or_int _:Rational = true; is_rat_or_int _:Int = true; is_rat_or_int _ = false; I'm not sure the type guard "C:Complex" and function application "iscomplex C" should be related this closely; Similarly for "Q:Rational" and "is_rational Q". Perhaps these should be iscomplex _:Complex = true; iscomplex R = isreal R otherwise; //behavioural change isreal _:Real = true; isreal Q = isrational Q otherwise; // this won't work unless rational.q is included (or preluded) // thus might need to do e.g. "isint Q or else ..." isrational _:Rational = true; // slight rename isrational Z = isint Z otherwise; //behavioural change /* (scrap is_rat_or_int) */ isint _:Int = true; isint _ = false otherwise; (On the other hand, I think it would be wrong for Real to be a subtype of Complex.) I think I need clarification on (1) When one type should be a subtype of another. (2) What the semantics of type test function (such as iscomplex) is supposed to be. For example, for (1), suppose that there are the following types: Num | | C[R] denoting Complex [with Real parts] / \ / \ C[Q] R = Real / \ / / \ / C[Z] Q = Rational \ / \ / Z = Int (C[Z] is the ring of Gaussian Integers.) Should these types be related as supertype:subtype, and can Q express these (especially where there is more than one supertype)? Alternatively, should the only relationships be with Num as the common supertype? For (2), should e.g. "iscomplex" mean "is of Complex type or has a value that may be expressed (exactly?) as a Complex". (I'm ignoring, for the moment, the problem that a large Int can only be converted approximately to a Float. I'm assuming that Real and Float are equivalent.) I'd appreciate any feedback; it would help with my rational.q and an experimental "hypercomplex.q" that I'm (tentatively) working on. Thanks, Rob. |