ModelicaSpecification icon indicating copy to clipboard operation
ModelicaSpecification copied to clipboard

Partial application and default binding.

Open qlambert-pro opened this issue 2 years ago • 2 comments

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?

qlambert-pro avatar Sep 05 '22 09:09 qlambert-pro

I would say that both are incorrect.

HansOlsson avatar Sep 06 '22 14:09 HansOlsson

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.

qlambert-pro avatar Sep 08 '22 04:09 qlambert-pro

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 input e and then the requirement is that it must have a binding assignment in f, which it has so it is legal.
  • In the second case the input e exists with a binding assignment in scalarF, and thus it must have exist with a binding assignment in f, 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).

HansOlsson avatar Nov 22 '22 13:11 HansOlsson

(Pressed return too early due to internet problem.) That was a potential unclarity, but it seems clear enough.

HansOlsson avatar Nov 22 '22 13:11 HansOlsson

To me this seems clear enough.

HansOlsson avatar Nov 23 '22 09:11 HansOlsson

Agreed

qlambert-pro avatar Nov 23 '22 09:11 qlambert-pro