0
votes

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`
1
I think you should give us some more examples :) (especially about the tuple stuff you mentioned last.)huon
Also, stop, Hoogle time! (partition sounds most useful.)huon
I did look partition but dont quite see how it apply to my tupple. In fact i have done all the fct that need to be applied i need to understand how to go thru tupplet and replace tuplets by new one until it reach []Frédéric Lacoste Bienvenue
@FrédéricLacosteBienvenue: Please put in your answer as an answer and mark it as correct. Check out the FAQ for more details. Right now people are reading your question thinking that you still need helpSheena

1 Answers

0
votes
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`