Actually, replacing modifySTRef with that code is just a hair slower... Not sure why.
I'm attaching the super optimized version. Along with the profiler output. I just can't understand what is slow here :(
Timothy
---------- Původní zpráva ----------
Od: Felipe Almeida Lessa <felipe.lessa@gmail.com>
Datum: 3. 9. 2012
Předmět: Re: [Haskell-cafe] hstats median algorithm
On Mon, Sep 3, 2012 at 11:18 AM, Felipe Almeida Lessa
<felipe.lessa@gmail.com> wrote:
> Ditto for oldLen here. Also, you can simplify this lambda a lot:
>
> import Control.Applicative ((<$>))
>
> \(oldLen, oldVal) ->
> let newLen = oldLen + 1
> newVal = (number:) <$> oldVal
> in newLen `seq` newVal `seq` (newLen, newVal)
Or, using BangPatterns,
\(oldLen, oldVal) ->
let !newLen = oldLen + 1
!newVal = (number:) <$> oldVal
in (newLen, newVal)
Cheers,
--
Felipe.