[Haskell-cafe] efficient chop
Sean Leather
leather at cs.uu.nl
Thu Sep 15 14:39:11 CEST 2011
On Wed, Sep 14, 2011 at 17:31, Ivan Lazar Miljenovic wrote:
> On 15 September 2011 01:24, Sean Leather wrote:
> > On Wed, Sep 14, 2011 at 05:03, Kazu Yamamoto wrote:
> >>
> >> I would like to have an efficient implementation of the chop function.
> >
> > [...]
> >
> >>
> >> Are there any more efficient implementations of chop? Any suggestions?
> >
> > chop xs = go xs id ""
> > where
> > go "" _ = id
> > go (c:cs) ss | isSpace c = go cs (ss . (:) c)
> > go (c:cs) ss | otherwise = ss . (:) c . go cs id
>
> Why the extra case for go? The otherwise guard can be part of the
> second case...
Do you mean "why include 'go (c:cs) ss' twice"? That's merely because I was
working through several versions and forgot to merge the second and third
cases before sending the email. Nothing sinister.
Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110915/630b8512/attachment.htm>
More information about the Haskell-Cafe
mailing list