[Aldor-l] Special casing...
Christian Aistleitner
tmgisi at gmx.at
Tue Feb 20 06:32:43 EST 2007
Hello,
> do you think that something like (i.e., achieving the same or a similar
> effect as) the following is possible in Aldor (or in improved SPAD):
>
> I'd like the compiler to allow something like
>
> ---------------------------------------------------------------------------
> f(a: S): T == { generic implementation }
>
> f(specialValueOfTypeS): T == { special implementation for
> specialValueOfTypeS }
> f(otherSpecialValueOfTypeS): T == { special imp. for
> otherSpecialValueOfTypeS }
>
> g(c: T, d: T): T == { ... f(c) ... f(d) ...}
> ---------------------------------------------------------------------------
>
> So, if c happens to be specialValueOfTypeS, then the special
> implementation is
> used, and so on.
without further machinery, I'll doubt that this is possible. And I
strongly disadvise you to use such a design.
You are mixing different programming paradigms here. But I am sure you
thought about this problem and the arising confusion and problems.
If your domain S provides equality checks (PrimitiveType for Aldor), you
can get something not too far from what you wanted to have while still
being extensible. For example by using dictionaries (the value of s being
the key and the various special implementations of f the values). Hiding
the use of dictionaries within macros should give you the possibility to
cancel them out and eliminate the overhead, if Aldor chooses to allow
this type of programming.
Whether such a design is really applicable depends on how badly you need
extensibility.
Kind regards,
Christian
More information about the Aldor-l
mailing list