[Haskell-cafe] Missing join and split
Andrew Coppin
andrewcoppin at btinternet.com
Fri Dec 28 06:38:10 EST 2007
Mitar wrote:
> Hi!
>
> I am really missing the (general) split function built in standard
> Haskell. I do not understand why there is something so specific as
> words and lines but not a simple split? The same goes for join.
>
> Yes, I can of course define them but ... in an interactive mode it
> would be quite handy to have them there.
>
> Or am I wrong and are those hidden somewhere?
>
> So what are common ways to get around this? What are elegant
> definitions? Inline definitions?
>
As I understand it, they don't exist because nobody can agree on the
best way to define them.
For joining you probably want some combination of intersperse and
concat, e.g.
unlines = concat . intersperse "\n"
For splitting, do we split on a given character? A predicate? Do we keep
the splitting character or throw it away? Do we generate empty sublists
or elide them? Apparently nobody can agree on these points, and writing
a function with all possible options would be very messy...
More information about the Haskell-Cafe
mailing list