[plt-scheme] find out return type of a function in typed scheme
>
> What are you using this information for? That might help me make it
> easier for you.
I'm trying to implement relational algebra according to the Chris Date books, and there I have "Attributes" (making up the relation's heading) consisting of a name and a type tag, as well as "Triples" (making up the relation's body) with the same two fields, plus
a value field, like this:
(define-struct: Triple ((name : String) (typename : Symbol) (value : Value)))
(define-struct: Attribute ((name : String) (typename : Symbol)))
[Currently the only possible types for values, and so the only possible type names, are numbers and strings.]
Right now I'm at the Extend operator, which adds a new Attribute & Triple to the relation:
(define-datatype RelExpr
...
(Extend ((r : RelExpr) (e : Extlist))))
(define-type Extlist (Listof Extension))
(define-struct: Extension ((operand : Operand) (name : String)))
(define-datatype Operand
(Att ((att : Attribute)))
(Val ((val : Value)))
(App ((op : Operator) (o1 : Operand) (o2 : Operand))))
Now when I evaluate the Extend, I have to construct a new Attribute/Triple, but in case the Operand is an "App ...." I have to find out what type tag to give it. I can evaluate the expression, but it would seem more natural to query for the return type of the Operator.
--- In fact now that I'm trying to describe it, I notice the concept of Operator is not clear at all in my code (in fact it's all a bit bottom-up, adding concepts as relational operators make them necessary :-;) .
I started out with boolean comparisons, added arithmetic operators as a placeholder/example for both arithmetic and string functions (the ones I need for my 2 value types). But I think I have some confusion here, - starting out with boolean vs. arithmetic operators made me define a
(define-type Operator (U Arith-Op Bool-Op))
but now, integrating the string handling and building the new Attribute, I'm looking for the return type really (I cannot have a String-Op like in the Arith-Op case as an operation on strings can return a number too...)
Seems like I have to think this through first (but not today as it's late here already :-;), I hope you'll excuse me taking your time with this "half-baked" stuff...
Best greetings and thanks,
Sigrid
>
>> I can get along with the workaround, only the other way would be more
>> natural (if possible).
>> Would there be a way to offer this information by some "convenience
>> function", not necessitating exposal of the internal representation? But
>> really it's not that urgent, I was just asking to be sure I don't oversee it
>> in the documentation :-;
>
> The problem with that is that if I changed the internal
> representation, your code would break, since I'd just be returning
> some struct from the implementation that might be different from
> release to release.
>
> --
> sam th
> samth at ccs.neu.edu