I have currently defined two functions:
avg :: (Fractional e) => [e] -> e avg e = uncurry (/) $ foldl' (\(a,l) v -> (a+v,l+1)) (0.0,0.0) e avgOf :: (Fractional a) => Getting (Endo (Endo (a, a))) sa -> s -> a avgOf gs = uncurry (/) $ foldlOf' g accfun (0.0,0.0) s where accfun (a,l) v = (a+v, l+1)
I get the impression that there should be an easy way to get rid of the whole avgOf implementation and replace it with a simple one that just βraisesβ avg for working with lenses.
source share