Use the 'sortBy' and 'group' functions from Data.List. The rest is quite easy. Or you might use a Data.Map (degree => coefficient), particularly the fromListWith function.
2010/1/19 jjoshua <[email protected]>: > > So I defined a type called term which is a coefficient and degree of x. int a > int b. > I want to write a method/methods in haskell to sort them and combine ones > with same degree. I think I need to combine somehow, and then use sortby > method? I'm just learning haskell, but I now java and c# pretty well and I'm > having a hard term converting to functional thinking. > its of type [(Int a Int b)] and if b1< b2 put tuple 1 before tuple2, else if > = combine by adding a1 to a2, else place 2 before 1. I know how to do it > logically, just not the syntax I guess. > Thanks so much guys! > -- > View this message in context: > http://old.nabble.com/sorting-and-merging-in-haskell-tp27222668p27222668.html > Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. > > _______________________________________________ > Haskell-Cafe mailing list > [email protected] > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Eugene Kirpichov Web IR developer, market.yandex.ru _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
