[Haskell-cafe] is there a way to prove the equivalence of these two implementations of (Prelude) break function?

Daniel Fischer daniel.is.fischer at web.de
Tue Jun 8 08:31:29 EDT 2010


On Tuesday 08 June 2010 08:33:51, David Virebayre wrote:
> 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. )

Aye. I'm not sure whether there's a difference with -O2, but it's 
substantial without optimisations.

>
> David.



More information about the Haskell-Cafe mailing list