List Grouping module released

14/08/2009

EDIT: Don’t use this package, but use instead Data.List.Split by Brent Yorgey. I didn’t see that a package like his existed! This module will hopefully be removed from hackage if they can do that.

I just finished the initial release of a simple module called list-grouping that contains functions to partition a list into sub-lists in various ways, based on some predicate or integer offset. Functions like these are a little awkward to write and I was surprised when I didn’t see anything on hackage!

Check out the package description and install it with:

$ cabal install list-grouping

Here is an example from a previous post to build a binary tree from an in-order list, which uses the above library:


module Main
    where

import Data.List.Grouping

data Tree a = Node a (Tree a) (Tree a)
            | End
             deriving Show

fromSorted :: [a] -> Tree a
fromSorted = foldl mkTree End . splitWith [2^| n<-[0..]]
    where mkTree l (n:ns) = Node n l (fromSorted ns)

I’m sure the functions can be made more efficient, to take advantage of fusion or what-not, and I hope the library will eventually contain the most efficient implementations possible.

I also am looking for suggestions for other useful list grouping functions to include. Send your suggestions along! You can get the darcs source with:

$ darcs get http://coder.bsimmons.name/code/ListGrouping/

There are 2 comments in this article:

  1. 14/08/2009Krzysztof Skrzętnicki says:

    Can you compare it with split package?

    http://hackage.haskell.org/package/split

    From a quick glance at your library it can do as much yours and probably more.

  2. 17/08/2009jberryman says:

    Thanks Krzysztof,

    I was under the impression that Hoogle was indexing all of the packages on Hackage, and just assumed that the functions in my library didn’t exist in a package yet. What a waste of time!

    Looking into getting the package removed.

Write a comment: