    {-# LANGUAGE FlexibleContexts #-}

    -- |
    -- Module    : Statistics.Sample.Internal
    -- Copyright : (c) 2013 Bryan O'Sullivan
    -- License   : BSD3
    --
    -- Maintainer  : bos@serpentine.com
    -- Stability   : experimental
    -- Portability : portable
    --
    -- Internal functions for computing over samples.
    module Statistics.Sample.Internal
        (
          robustSumVar
        , sum
        ) where

    import Numeric.Sum (kbn, sumVector)
    import Prelude hiding (sum)
    import Statistics.Function (square)
    import qualified Data.Vector.Generic as G

    robustSumVar :: (G.Vector v Double) => Double -> v Double -> Double
    robustSumVar :: forall (v :: * -> *).
    Vector v Double =>
    Double -> v Double -> Double
    robustSumVar Double
    m = v Double -> Double
    forall (v :: * -> *). Vector v Double => v Double -> Double
    sum (v Double -> Double)
    -> (v Double -> v Double) -> v Double -> Double
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Double -> Double) -> v Double -> v Double
    forall (v :: * -> *) a b.
    (Vector v a, Vector v b) =>
    (a -> b) -> v a -> v b
    G.map (Double -> Double
    square (Double -> Double) -> (Double -> Double) -> Double -> Double
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Double -> Double -> Double
    forall a. Num a => a -> a -> a
    subtract Double
    m)
    {-# INLINE robustSumVar #-}

    sum :: (G.Vector v Double) => v Double -> Double
    sum :: forall (v :: * -> *). Vector v Double => v Double -> Double
    sum = (KBNSum -> Double) -> v Double -> Double
    forall (v :: * -> *) s.
    (Vector v Double, Summation s) =>
    (s -> Double) -> v Double -> Double
    sumVector KBNSum -> Double
    kbn
    {-# INLINE sum #-}