Pattern matching is-expressions
Stefan Koch
uplink.coder at googlemail.com
Wed Aug 19 09:53:41 UTC 2020
On Wednesday, 19 August 2020 at 07:29:18 UTC, Stefan Koch wrote:
> Hi there,
>
> Recently I have been thinking about converting commonly used is
> expressions into __traits,
> since having that makes type functions more consistent.
>
[ ... ]
There is even more inconsistency, which comes from the fact that
pattern matching is expressions are not actually able to match
arbitrarily complex patterns.
You cannot even use it to extract parts from a function type.
which is why the other wired forms exist
for an example look at this:
package void invert(double[] from) {
from[] *= 7.0;
pragma(msg, typeof(invert)); // output void(double[] from)
pragma(msg, is(void function (double[]))); // true void
function (double[]) is a type
pragma(msg, is(typeof(invert) == function)); // true typeof
invert is a function
pragma(msg, is(typeof(invert) == void function(double[])));
// false ???
pragma(msg, is(typeof(invert) == R function (A),
R, A)); // also false, that would suggest that typeof(invert) is
actually function without return type or parameters.
// what we see here is that is expressions are broken.
// pragma(msg, is(typeof(invert) == R F (A), R, A, F)); //
if it's not a function let F be a free symbol as well
// answer: expected identifier `F` in declarator
// this is a parser error
// therefore the line had to be commented out
}
the same code is also at: https://run.dlang.io/is/76q4wG
More information about the Digitalmars-d
mailing list