digitalmars.D - Re: equivariant functions
- ore-sama <spam here.lot> Oct 14 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.
Oct 14 2008