Created
June 15, 2014 19:31
-
-
Save Shimuuar/bf2ccc0fce34e3cb037b to your computer and use it in GitHub Desktop.
Jackknife
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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