[Haskell-cafe] Re: Why is there no splitBy in the list module?

Donald Bruce Stewart dons at cse.unsw.edu.au
Wed Jul 12 04:55:50 EDT 2006


simonmarhaskell:
> >I guess the problem with the splitWith thing is that it's a slippery
> >path that leads right up to full-on parsers.
> 
> Exactly, and this is why we didn't reach a concensus last time.
> 
> Would someone like to make a concrete proposal (with code!) for 2-3 
> functions we could reasonably add to Data.List?

No parsers!

I vote for this, currently implemented in Data.ByteString:
        
    -- | split on characters
    split        :: Char -> String -> [String]

    -- | split on predicate *
    splitBy      :: (Char -> Bool) -> String -> [String]

and
    -- | split on a string
    tokens       :: String -> String -> [String]

Question over whether it should be:
    splitBy (=='a') "aabbaca" == ["","","bb","c",""]
  or
    splitBy (=='a') "aabbaca" == ["bb","c"]

I argue the second form is what people usually want.

-- Don


More information about the Libraries mailing list