[Haskell-cafe] Utility functions
Derek Elkins
ddarius at hotpop.com
Tue Dec 28 21:56:56 EST 2004
> I find myself writing things like,
>
> splitListOn :: Eq a => a -> [a] -> [[a]]
>
> splitListOn delimiter =
> unfoldr splitter . (delimiter :)
> where
> splitter [] = Nothing
> splitter xs = Just (span (/= delimiter) (tail xs))
>
> This is a sort of intersperse-opposite, in that...
>
> myId delimiter = concat . intersperse [delimiter] . splitListBy
> delimiter
>
> ...myId foo turns into a sort of id for lists of the correct type.
>
> With this, and other things, I always have a feeling that it's
> probably in the standard library somewhere but I didn't notice - maybe
> because it's abstracted out of recognition, just like "sequence" does
> Cartesian products for us, but not so that I noticed right away.
>
> Is there a good place to put these things - little things that feel
> like that maybe they're already in the standard library, and maybe
> they should be? I'd hate to be unknowingly reinventing the wheel all
> the time. I don't see an obviously-appropriate page for these on the
> Haskell Wiki, but maybe I missed it, or maybe I should create one.
I created a page a short while back that I haven't linked in anywhere
(so it's currently an orphan page modulo being in CategoryCodeSnippet)
called http://www.haskell.org/hawiki/CodeOnTheWiki that links to various
parts of the wiki containing good chunks of code. The first three links
seem most appropriate.
A page about Haskell's "hidden" library functions may be useful. There
are many functions that seem to be reimplemented that are, as you well
put it, "abstracted out of recognition," to varying degrees and often
reimplemented. For example, another is the mplus instance of Maybe
which is useful but has no (other) equivalent library function and is
often reimplemented (e.g. darcs' or_maybe
http://www.haskell.org/pipermail/haskell-cafe/2003-December/005617.html).
More information about the Haskell-Cafe
mailing list