Skip to content

Instantly share code, notes, and snippets.

@Shimuuar
Created June 15, 2014 19:31
Show Gist options
  • Save Shimuuar/bf2ccc0fce34e3cb037b to your computer and use it in GitHub Desktop.
Save Shimuuar/bf2ccc0fce34e3cb037b to your computer and use it in GitHub Desktop.
Jackknife
import Data.Monoid
-- | Type class for monoidal accumulators
class Monoid m => Accumulator m a where
-- | Convert value to 1-element accumulator
unit :: a -> m
unit a = cons a mempty
-- | Prepend value to accumulator
cons :: a -> m -> m
cons a m = unit a <> m
-- | Append value to accumulator
snoc :: m -> a -> m
snoc m a = m <> unit a
jackknifeMean :: Accumulator m a => [a] -> [m]
jackknifeMean xs =
zipWith mappend
(init (scanl snoc mempty xs))
(tail (scanr cons mempty xs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment