I have a function, lets call it fct1
, that take any list and get all the equal one in a list and all the rest in a second list and they are inside a tuple.
data sale : ( sale string int)
fct1 [sale,sale..sale]
will return only the sale that have the string identical on the first list and all the other in the second)
ex on number (easier to understand): fct1 [1,2,3,4,6,7,1,3,4]= ([1,1],[2,3,4,6,7,3,4])
And I have a second function, lets call it fct2
.
fct2
is applied always on the fst(tuple) and I need to accumulate the result into a list. And the list will be the return value
I need to apply a fct2
on fst(tuple) then apply the same fct1
on the snd(tuple) so it recreate a tuple with the rest until I reach a fct1 =[]
I know I have to do it recursively, just don't know where to start...fct1
and fct2
too.
here is the my pseudocode...
type Qty = Integer
type Product =string
data Sales = Sales Product Qty`
as is a list
fct1 = (fct1 (\(Sales product qty) -> product == product(head as)) as)
it return a tuple (list1,list2)
fct2:
the fct1 need to be run on the snd(tuple) so i reach [] as snd(tuple) and at the same time i need to run on the fst(tuple) fct2 that take the list and summarize it into one lement that i need to keep and accumulate into a single list.
I hope I'm more explicit this time..
FOUND THE SOLUTION HERE IS THE CODE:
fct2 as = accSales [] as
where accSales n as =
if as == []
then sortBy compareSale n
else let x =sumQty(fst(fct1(as)))
xs = snd(fct1(as))
in accSales (x:n) xs`
partition
sounds most useful.) – huon