<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    <tt><big>I don't know what this tuple is representing, but if you
        want to group you'll have to specify on 'what':<br>
        - the tuple,<br>
        - the fst or<br>
        - the snd<br>
        <br>
        Here's a possibility with grouping on the fst<br>
        <br>
        import Data.List<br>
        import Data.Ord<br>
        import Data.Function<br>
        <br>
        groupAtoms ::<br>
          (Float -&gt; Bool)<br>
          -&gt; [(Float,Integer)]<br>
          -&gt;  ([[(Float,Integer)]],[[(Float,Integer)]])<br>
        groupAtoms p = partition (p.sum. map fst). groupBy
        ((==)`on`fst). sortBy (comparing fst)<br>
        <br>
        Use:<br>
        <br>
        groupAtoms (&gt;=1.0) myList<br>
        <br>
        If this is what you want: proper lists are in the fst of the
        result.<br>
        <br>
        <br>
      </big><br>
    </tt> <br>
    <br>
    Hallo João Paulo Pizani Flor, je schreef op 23-11-10 18:23:
    <blockquote
      cite="mid:AANLkTinJ2em8cQrFzaCANAiDKdig4dNON_4g8q5Hnacj@mail.gmail.com"
      type="cite">
      <div>Hello dear Haskellers!</div>
      <div><br>
      </div>
      <div>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</div>
      <div><br>
      </div>
      <div>OK, so my specific problem goes like this: I have a list of
        tuples</div>
      <div><font class="Apple-style-span" face="'courier new',
          monospace">:t  myList</font></div>
      <div><font class="Apple-style-span" face="'courier new',
          monospace">[ (Float, Integer) ]</font></div>
      <div><br>
      </div>
      <div>And I want to "group" this list into a nested list</div>
      <div><font class="Apple-style-span" face="'courier new',
          monospace">groupAtoms :: [ (Float,Integer) ]  -&gt;  [
          [(Float,Integer)] ]</font></div>
      <div><br>
      </div>
      <div>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:</div>
      <div>"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:</div>
      <div><font class="Apple-style-span" face="'courier new',
          monospace">\g -&gt; sum (map fst g)  &gt;=  1.0</font></div>
      <div><br>
      </div>
      <div><br>
      </div>
      <div>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</div>
      <div>to help me, but only now I see I'm still a big noob :P</div>
      <div><br>
      </div>
      <div>Could someone please help me writing this function?</div>
      <div><br>
      </div>
      <div><br>
      </div>
      <div>My best regards from Brazil,</div>
      <div> <br>
      </div>
      João Paulo Pizani Flor
      <div><a moz-do-not-send="true" href="mailto:joaopizani@gmail.com"
          target="_blank">joaopizani@gmail.com</a></div>
      <div>Federal University of Santa Catarina</div>
      <br>
      <pre wrap=""><fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://www.haskell.org/mailman/listinfo/beginners">http://www.haskell.org/mailman/listinfo/beginners</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="80">-- 
Met vriendelijke groet,
=@@i
</pre>
  </body>
</html>