equivariant functions

ore-sama spam at here.lot
Tue Oct 14 01:45:07 PDT 2008


Andrei Alexandrescu Wrote:

> I'm glad there's interest in equivariant functions. Let me share below 
> how I think they can be properly typechecked.
> 
> The general signature of an equivariant function is:
> 
> typeof(expression_involving(pk)) fun(T1 p1, ..., Tk pk, ..., Tn pn);
> 
> Let's see this typechecking at work:
> 
> 1. Accessing a field:
> 
> typeof(s.ptr) at(const char[] s, uint i) { return s.ptr + i; }
> 
> Typecheck with a typedef for const char[], yielding:
> 
> typedef const(char[]) __Surrogate;
> typeof(__Surrogate.init.ptr) at(__Surrogate s, uint i)
> { return s.ptr + i; }
> 
> Pass.

How to typecheck it in the case of mutable argument?
typedef surrogate as mutable type?

In all three variants of function only const and/or equivariant methods should be called on surrogated parameter.



More information about the Digitalmars-d mailing list