[Haskell-cafe] Removing alternate items from a list

John Meacham john at repetae.net
Wed Jun 9 19:39:07 EDT 2010


On Wed, Jun 09, 2010 at 11:47:32PM +0300, Markus Läll wrote:
> As the function doing (x:_:rest) pattern-matching was the fastest I
> extended the idea from that to (x1:_:x2: ... x10:_:rest), but skipping
> from 5 to 10, where all steps showed a small increase in performance.
> 
> So a question: when increasing the pattern matched, is it somekind of
> way of inlining the matchings, and if so, is there some way of just
> saying that to the compiler how many recursions you want to inline
> together to increase speed?

What you are describing is somewhat akin to a loop unrolling
optimization, which is a fairly common thing for a compiler to do.
However, as you described it, it is not actually a valid optimization in
haskell. compare

take 2 (matchPattern5 (1:2:3:4:undefined)) => undefined
take 2 (matchPattern  (1:2:3:4:undefined)) => [1,3]

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/


More information about the Haskell-Cafe mailing list