2

以下が機能するのはなぜですか:

rascal>int increment(int x) = x + 1;
int (int): int increment(int);

rascal>int s = 5;
int: 5

rascal>increment(s);
int: 6

rascal>value vs = s;
value: 5

rascal>increment(vs);
int: 6

...これは失敗しますが:

rascal>data Side = leftSide() | rightSide();
ok

rascal>Side swap(leftSide()) = rightSide();
Side (Side): Side swap(Side);

rascal>Side swap(rightSide()) = leftSide();
Side (Side): Side swap(Side);

rascal>Side side = leftSide();
Side: leftSide()

rascal>swap(side)
Side: rightSide()

rascal>value vside = side;
value: leftSide()

rascal>swap(vside)
|stdin:///|(0,11,<1,0>,<1,11>): The called signature: swap(value),
does not match the declared signature:  Side swap(Side); (abstract pattern);  Side swap(Side); (abstract pattern);
4

1 に答える 1