Opened 10 years ago

#2828 new defect

Function partial application sometimes results in type mismatch

Reported by: Per Östlund Owned by: Martin Sjölund
Priority: high Milestone: Future
Component: MetaModelica Version: trunk
Keywords: Cc:

Description

Defining map1Fold like this causes an error:

function mapFold<TI, TO, FT>
  "Takes a list, an extra argument and a function. The function will be applied
  to each element in the list, and the extra argument will be passed to the
  function and updated."
  input list<TI> inList;
  input FuncType inFunc;
  input FT inArg;
  output list<TO> outList := {};
  output FT outArg := inArg;

  partial function FuncType
    input TI inElem;
    input FT inArg;
    output TO outResult;
    output FT outArg;
  end FuncType;
protected
  TO res;
algorithm
  for e in inList loop
    (res, outArg) := inFunc(e, outArg);
    outList := res :: outList;
  end for;
  outList := listReverse(outList);
end mapFold;

public function map1Fold<TI, TO, FT, ArgT1>
  "Takes a list, an extra argument, an extra constant argument, and a function.
  The function will be applied to each element in the list, and the extra
  argument will be passed to the function and updated."
  input list<TI> inList;
  input FuncType inFunc;
  input ArgT1 inConstArg;
  input FT inArg;
  output list<TO> outList := {};
  output FT outArg := inArg;

  partial function FuncType
    input TI inElem;
    input ArgT1 inConstArg;
    input FT inArg;
    output TO outResult;
    output FT outArg;
  end FuncType;
algorithm
  (outList, outArg) := mapFold(inList, function inFunc(inConstArg = inConstArg), inArg);
end map1Fold;

The error is:

Error: Type mismatch in pattern outList
expression type:
  list<polymorphic<$inFunc.TO>>
pattern type:
  list<polymorphic<TO>>

I.e. it thinks the types are different when they should be the same.

Change History (0)

Note: See TracTickets for help on using tickets.