[Haskell-cafe] Utility functions

Mark Carroll markc at chiark.greenend.org.uk
Tue Dec 28 12:54:09 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.

-- Mark



More information about the Haskell-Cafe mailing list