ModelicaSpecification
ModelicaSpecification copied to clipboard
Partial application and default binding.
Consider:
model PartialCall
type E = enumeration(one, two);
function f
input Real u;
input Real i;
input E e = E.one;
output Real y;
algorithm
y := u + i;
end f;
partial function scalarF
input Real i;
output Real o = i;
end scalarF;
function g
input scalarF f;
input Real v;
output Real o = f(v);
end g;
Real x = g(function f(i = 1), 2);
end PartialCall;
and
model PartialCall2
type E = enumeration(one, two);
function f
input Real u;
input Real i;
input E e = E.one;
output Real y;
algorithm
y := u + i;
end f;
partial function scalarF
input Real i;
input E e = E.one;
output Real o = i;
end scalarF;
function g
input scalarF f;
input Real v;
output Real o = f(v);
end g;
Real x = g(function f(i = 1), 2);
end PartialCall2;
is the consensus that PartialCall
is invalid because of function type incompatibility but PartialCall2
is valid?
I would say that both are incorrect.
Can you explain on which basis, you would reject PartialCall2
? Btw, it seems to me that both can't be invalid at the same time unless we forbid the partial application of function with default binding.
My problem with the example is a tangential issue; the partial function should be function compatible and that implies the same name and order for remaining arguments, but the unbound input for function f
is u
- whereas it is called i
for scalarF
.
That would be simple to fix.
Ignore that and focus on the actual issue, is the applied function f function compatible to scalarF?
- In the first case
scalarF
lacks the inpute
and then the requirement is that it must have a binding assignment inf,
which it has so it is legal. - In the second case the input
e
exists with a binding assignment inscalarF
, and thus it must have exist with a binding assignment inf
, which it has so it is legal. - Note that if the call was
function f(i = 1, e=E.one)
then the first example would be legal - but the second one illegal.
The only unclarity I can find is whether it is specified which function should be function compatible to which one (it is not a symmetric relation).
(Pressed return too early due to internet problem.) That was a potential unclarity, but it seems clear enough.
To me this seems clear enough.
Agreed