Prelude function suggestions

Donald Bruce Stewart dons at cse.unsw.edu.au
Wed Jul 28 05:25:17 EDT 2004


simonmar:
> On 27 July 2004 23:44, ariep at xs4all.nl wrote:
> 
> >> {- | Split the list at the occurrences of a separator into sub-list.
> >>      This is a generalization of 'words'. -}
> >> chop :: (a -> Bool) -> [a] -> [[a]]
> >> chop p s =
> >>    let (l, s') = break p s
> >>    in  l : case s' of
> >>            [] -> []
> >>            (_:rest) -> chop p rest
> > 
> > I like 'chop'. It belongs in Data.List, I'd say.
> 
> We have something very like this inside GHC, except we call it 'split'.
> It's very useful for splitting up file paths into components.
> 
> For comparison, Perl calls it 'split'.  In Perl, 'chop' does something
> different.  Python also has a 'split' function that does something
> similar.
> 
> Does anyone object to calling it 'split'?

I often have the need to write this function. Sometimes it gets called
split, sometimes psplit (p for perl) :)

-- Don


More information about the Libraries mailing list