[Aldor-l] Specifying properties of functions

Christian Aistleitner tmgisi at gmx.at
Tue Mar 29 02:14:03 EST 2005


Hi,

the folloming reply does not address Ralf's problem of compiling a file.
However it belongs into this thread, since it meets the subject line and  
discusses Ralf's design of „specifying properties of functions”.

I am convinced that Ralf suggestion is a good starting point for a  
discussion and will try to list pros and cons of three alternatives.




> define CommutativeRing: Category == Ring with {...}
>
> It is implicitly understood that * is the function that "commmutative"
> refers to.

This is the plain specification of the Algebra's CommutativeRing.
PROS:
  + simple
CONS:
  - does not deal with the fact that function „*” itself is commutative.




> define Commutative(D: Type, f: (D, D) -> D): Category == with;
PROS:
  + reflects the fact that „*” is commutative
  + resolved at compile-time
CONS:
  - needs a wrapping of the function in a category
  - the property does not stick to the function
  - needs (undeveloped) Aldor support to be safe




I would like to add a further approach to this topic – namely  
Mathematica's approach.
Mathematica adds Attributes to functions themselves.

In Mathematica it is possible to define a function and assert attributes  
afterwards. Of course these Attributes can also be extracted.
See for example:
http://documents.wolfram.com/mathematica/functions/Attributes
http://documents.wolfram.com/mathematica/Built-inFunctions/Programming/Attributes/FurtherExamples/Attributes.html
http://documents.wolfram.com/mathematica/functions/SetAttributes
http://documents.wolfram.com/mathematica/Built-inFunctions/Programming/Attributes/FurtherExamples/SetAttributes.html

PROS:
  + reflects the fact that „*” is commutative
  + the property sticks to the function
CONS:
  - needs (undeveloped) Aldor support to be safe
  - currently only possible to build with run-time checks, not resolved at  
compile-time checks


However, I am  not sure, which of these three ways is the most appropriate  
one.
The first approach is simple, but not flexible.
The second approach does not introduce run-time overhead, but looks like a  
decoupling of a function and its properties to me.
The third approach adds run-time overhead. This overhead might at some  
time get eleminated by some compiler support – but is it worth it?

Best regards,
Christian



More information about the Aldor-l mailing list