[Haskell-beginners] Problem "grouping" a list

João Paulo Pizani Flor joaopizani at gmail.com
Tue Nov 23 12:23:28 EST 2010


Hello dear Haskellers!

I've been a user and big fan of Haskell for a while, but only now I'm
writing my first "big" project in Haskell (some thousands of lines of code
perhaps). It's an interpreter for a programming language, the source code is
music! Yes, sheet music! :D

OK, so my specific problem goes like this: I have a list of tuples
:t  myList
[ (Float, Integer) ]

And I want to "group" this list into a nested list
groupAtoms :: [ (Float,Integer) ]  ->  [ [(Float,Integer)] ]

Of course, I want that the concatenation of the groups yield me the original
list, i.e,  (foldl (++) [] . groupAtoms == id), and the criterion that
defines a group is that:
"The sum of the first elements in the tuples comprising the list must be
greater than or equal to 1.0". That is, given a list of tuples, the boolean
predicate deciding whether this list is a PROPER group (True) or TOO SMALL
(False) is:
\g -> sum (map fst g)  >=  1.0


Although the criterion is very clear, I've tried hard until now and couldn't
come up with a function for producing the nested list based on this grouping
criterion. I am sure that the Haskell Hierarchical Libraries have something
to help me, but only now I see I'm still a big noob :P

Could someone please help me writing this function?


My best regards from Brazil,

João Paulo Pizani Flor
joaopizani at gmail.com
Federal University of Santa Catarina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20101123/c97865cf/attachment.html


More information about the Beginners mailing list