[Haskell-cafe] is there a way to prove the equivalence of these
two implementations of (Prelude) break function?
David Virebayre
dav.vire+haskell at gmail.com
Tue Jun 8 02:33:51 EDT 2010
On Sun, Jun 6, 2010 at 5:10 AM, Thomas Hartman <tphyahoo at gmail.com> wrote:
> Here's two implementations of break, a snappy one from the prelude,
...
> prelbreak p xs = (takeWhile (not . p) xs,dropWhile (not . p) xs) --
> fast, more or less as implemented in prelude iiuc
I had a look at the prelude, and I was surprised to see there's 2 versions,
depending on a flag :
#ifdef USE_REPORT_PRELUDE
break p = span (not . p)
#else
-- HBC version (stolen)
break _ xs@[] = (xs, xs)
break p xs@(x:xs')
| p x = ([],xs)
| otherwise = let (ys,zs) = break p xs' in (x:ys,zs)
#endif
I'm curious why is it so, and which version is compiled in the platform or
the ghc binaries.
( my guess is USE_REPORT_PRELUDE compiles functions as defined in the
haskell report, but the other version is faster and used by default. )
David.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100608/5b48d9e9/attachment.html
More information about the Haskell-Cafe
mailing list