Proposal: Add split and splitWith (trac #2048)
dons at galois.com
Wed Jan 16 19:37:55 EST 2008
> > > One or the other should be changed so that these agree:
> > >
> > > *Main> split 'a' ""
> > > [""]
> > > *Main> Data.ByteString.Char8.split 'a' (Data.ByteString.Char8.pack "")
> > > Loading package array-0.1.0.0 ... linking ... done.
> > > Loading package bytestring-0.9.0.1 ... linking ... done.
> > > 
> > >
> > > although I couldn't say which is "right" OTTOMH...
> > I hadn't noticed. In my opinion the Data.List version is more consistent,
> You can show you can build it up from an inductive argument, yes. But
> the Data.ByteString version probably matches what I'd expect to happen
> much more - just a gut feeling.
It's been a long time since I looked at bytestring's split, and it was
never meant to be the last word on how to do this. Here are some of the
properties it has,
prop_splitsplitWith c xs = split c xs == splitWith (== c) xs
prop_joinsplit c xs = intercalate [c] (split c xs) == xs
Note here the funniness of lines, complicates the properties:
prop_linessplit xs =
lines xs == split '\n' xs ++ (if last xs == '\n' then [empty] else )
What properties relating to current List functoins does this split have?
(I don't want to block the inclusion, just want to get a sense of how it
fits into the existing code).
More information about the Libraries