[Haskell-cafe] hstats median algorithm

Felipe Almeida Lessa felipe.lessa at gmail.com
Mon Sep 3 16:19:22 CEST 2012


On Mon, Sep 3, 2012 at 11:18 AM, Felipe Almeida Lessa
<felipe.lessa at 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.



More information about the Haskell-Cafe mailing list