﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2828	Function partial application sometimes results in type mismatch	Per Östlund	Martin Sjölund	"Defining map1Fold like this causes an error:
{{{#!mo
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."	defect	new	high	Future	MetaModelica	trunk			
