I'm working in CPN ML, which is more or less the same as SML. I know for sure that the following part of code works:
color Product = string;
color Number = int;
color StockItem = record prod:Product * number:Number;
color Stock = list StockItem;
var x:StockItem; var s:Stock;
fun incrs(x:StockItem,s:Stock) =
if s=[] then [x]
else (if (#prod(hd(s)))=(#prod(x))
then {prod=(#prod(hd(s))),number=((#number(hd(s)))+(#number(x)))}::tl(s)
else hd(s):: incrs(x,tl(s)));
fun decrs(x:StockItem,s:Stock)= incrs({prod=(#prod(x)),
number=(~(#number(x)))},s)
Now my problem is that I need to keep the store for each shop (a student task). So I made following adaptions:
color Store = string;
color StockItem = record prod:Product * number:Number * store:Store;
fun incrs(x:StockItem,s:Stock) =
if s=[]
then [x]
else (if {(#prod(hd(s)))=(#prod(x)), (#STORE(hd(s)))=(#STORE(x))}
then {prod=(#prod(hd(s))),
STORE = (#STORE(hd(s))),
number=((#number(hd(s)))+(#number(x)))}::tl(s)
else hd(s):: incrs(x,tl(s)));
The last line of code doesn't seem to work though. Can anyone help me please? Thanks a lot !!